Sunday, March 24, 2019

Play with the cyphr package

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 without decrypting it first

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)



Counter