lock_file | R Documentation |
lock_file()
and unlock_file
can encrypt/decrypt any kind of file using an
RSA key pair. If your project doesn't have an RSA key pair, you can use
rsa_keygen()
to create one.
These functions use encrypt_envelope() / decrypt_envelope() to perform file encryption/decryption. See those functions to learn more about the encrypting/decrypting process.
lock_file(
file,
public_key = "./inst/ssh/id_rsa.pub",
suffix = ".lockr",
remove_file = TRUE
)
unlock_file(
file,
private_key = "./inst/ssh/id_rsa",
suffix = ".lockr",
remove_file = TRUE,
password = NULL
)
file |
A string with the file path to be encrypted/decrypted. For security reasons, encrypted files must end with the suffix parameter. |
public_key |
(optional) an |
suffix |
(optional) a string specifying the suffix to be added (when
encrypting)/removed (when decrypting) to/of the file. It must start with
|
remove_file |
(optional) a |
private_key |
(optional) an |
password |
(optional) only for protected keys. A string specifying
the password to read the private key. Avoid typing passwords on the
console, use askpass() instead (default: |
An invisible string containing the locked/unlocked file path.
Other lock/unlock functions:
lock_dir()
## Locking files
temp_dir <- tempfile("dir")
dir.create(temp_dir)
temp_file <- tempfile(tmpdir = temp_dir)
rsa_keygen(temp_dir)
con <- file(temp_file, "w+")
cat("Test", file = temp_file, sep = "\n")
list.files(temp_dir)
suppressWarnings(readLines(con))
close(con)
lock_file(temp_file, public_key = file.path(temp_dir, "id_rsa.pub"))
temp_file_locked <- paste0(temp_file, ".lockr")
con <- file(temp_file_locked, "rb")
list.files(temp_dir)
suppressWarnings(readLines(con))
close(con)
## Unlocking files
unlock_file(temp_file_locked, private_key = file.path(temp_dir, "id_rsa"))
list.files(temp_dir)
con <- file(temp_file, "r+")
readLines(con)
close(con)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.