Site icon R-bloggers

Play with the cyphr package

[This article was first published on Shige's Research Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The cyphr package seems to provide a good choice for small research group that shares sensitive data over internet (e.g., DropBox). I did some simple experiment myself and made sure it can actually serve my purpose.

I did my experiment on two computers (using openssl): I created the test data on my Linux workstation running Manjaro then I tried to access the data on a Windows 7 laptop.

For creating the data (Linux workstation):

library(cyphr)

# Create the test data

data_dir <- file.path(“~/Dropbox/temp_files”, “data”)
dir.create(data_dir)
dir(data_dir)

# Encrypt the test data

cyphr::data_admin_init(data_dir)

key <- cyphr::data_key(data_dir)


filename <- file.path(data_dir, “iris.rds”)

cyphr::encrypt(saveRDS(iris, filename), key)
dir(data_dir)

# Cannot read the data with decrypting it

readRDS(filename)

# Read the decrypted version of the data

head(cyphr::decrypt(readRDS(filename), key))

For accessing the data (Windows laptop):

library(cyphr)

key <- data_key(“C:/Users/Ssong/Dropbox/temp_files/data”, path_user = “C:/Users/Ssong/.ssh”)


# Make data access request

data_request_access(“C:/Users/Ssong/Dropbox/temp_files/data”, 
path_user = “C:/Users/Ssong/.ssh”)

On Windows 7,  the system cannot locate the public located in “~/.ssh”, which is pretty dumb.

Going back to the Linux workstation to approve the data access request:

# Review the request and approve (to share with other users)
req <- data_admin_list_requests(data_dir)
data_admin_authorise(data_dir, yes = TRUE)
data_admin_list_keys(data_dir)

Now I can access the data on my Windows laptop:

key <- data_key(“C:/Users/Ssong/Dropbox/temp_files/data”, path_user = “C:/Users/Ssong/.ssh”)

d <- decrypt( readRDS( “C:/Users/Ssong/Dropbox/temp_files/data/iris.rds”), key)



To leave a comment for the author, please follow the link and comment on their blog: Shige's Research Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.