View source: R/encrypt_wrapper.R
encrypt | R Documentation |
Wrapper functions for encryption. These functions wrap
expressions that produce or consume a file and arrange to encrypt
(for producing functions) or decrypt (for consuming functions).
The forms with a trailing underscore (encrypt_
,
decrypt_
) do not use any non-standard evaluation and may be
more useful for programming.
encrypt(expr, key, file_arg = NULL, envir = parent.frame()) decrypt(expr, key, file_arg = NULL, envir = parent.frame()) encrypt_(expr, key, file_arg = NULL, envir = parent.frame()) decrypt_(expr, key, file_arg = NULL, envir = parent.frame())
expr |
A single expression representing a function call that would be called for the side effect of creating or reading a file. |
key |
A |
file_arg |
Optional hint indicating which argument to
|
envir |
Environment in which |
These functions will not work for all functions. For example
pdf
/dev.off
will create a file but we can't wrap
those up (yet!). Functions that modify a file (e.g.,
appending) also will not work and may cause data loss.
# To do anything we first need a key: key <- cyphr::key_sodium(sodium::keygen()) # Encrypted write.csv - note how any number of arguments to # write.csv will be passed along path <- tempfile(fileext = ".csv") cyphr::encrypt(write.csv(iris, path, row.names = FALSE), key) # The new file now exists, but you would not be able to read it # with read.csv because it is now binary data. file.exists(path) # Wrap the read.csv call with cyphr::decrypt() dat <- cyphr::decrypt(read.csv(path, stringsAsFactors = FALSE), key) head(dat) file.remove(path) # If you have a function that is not supported you can specify the # filename argument directly. For example, with "write.dcf" the # filename argument is called "file"; we can pass that along path <- tempfile() cyphr::encrypt(write.dcf(list(a = 1), path), key, file_arg = "file") # Similarly for decryption: cyphr::decrypt(read.dcf(path), key, file_arg = "file")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.