WARNING: This function must be used with caution! Check the parameters carefully.
lock_dir()
and unlock_dir()
can encrypt or decrypt all files from a given
directory.
lock_dir(
dir = "./inst/extdata",
public_key = "./inst/ssh/id_rsa.pub",
suffix = ".lockr",
remove_file = TRUE
)
unlock_dir(
dir = "./inst/extdata",
private_key = "./inst/ssh/id_rsa",
suffix = ".lockr",
remove_file = TRUE,
password = NULL
)
A string indicating the directory to encrypt/decrypt. (default:
"./inst/extdata"
).
(optional) an openssl
RSA
public key or a string specifying the public key path. See rsa_keygen()
to learn how to create an RSA key pair (default:
"./inst/ssh/id_rsa.pub"
).
(optional) a string specifying the suffix to be added (when
encrypting)/removed (when decrypting) to/of the file. It must start with
.
(default: ".lockr"
).
(optional) a logical
value indicating if
the original file must be removed after the encryption/decryption process
(default: TRUE
).
(optional) an openssl
RSA
private key or a string specifying the private key path. See rsa_keygen()
to learn how to create an RSA key pair (default: "./inst/ssh/id_rsa"
).
(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: NULL
).
An invisible NULL
. These functions are called just for side
effects.
Other lock/unlock functions:
lock_file()
## Locking files
ssh_dir <- tempfile("ssh")
dir.create(ssh_dir)
rsa_keygen(ssh_dir)
#> Keys successfully created at '/tmp/Rtmpz70sWH/ssh181463e8e3c0'.
temp_dir <- tempfile("dir")
dir.create(temp_dir)
for (i in seq(5)) {
file.create(tempfile(tmpdir = temp_dir))
}
list.files(temp_dir)
#> [1] "file181413a056f8" "file1814239e1c8" "file181454f7c22f" "file18145843c12d"
#> [5] "file18146a6098c2"
lock_dir(temp_dir, public_key = file.path(ssh_dir, "id_rsa.pub"))
#> Locked file written at
#> '/tmp/Rtmpz70sWH/dir181434dba423/file181413a056f8.lockr'.
#> Locked file written at '/tmp/Rtmpz70sWH/dir181434dba423/file1814239e1c8.lockr'.
#> Locked file written at
#> '/tmp/Rtmpz70sWH/dir181434dba423/file181454f7c22f.lockr'.
#> Locked file written at
#> '/tmp/Rtmpz70sWH/dir181434dba423/file18145843c12d.lockr'.
#> Locked file written at
#> '/tmp/Rtmpz70sWH/dir181434dba423/file18146a6098c2.lockr'.
## Unlocking files
unlock_dir(temp_dir, private_key = file.path(ssh_dir, "id_rsa"))
#> Unlocked file written at '/tmp/Rtmpz70sWH/dir181434dba423/file181413a056f8'.
#> Unlocked file written at '/tmp/Rtmpz70sWH/dir181434dba423/file1814239e1c8'.
#> Unlocked file written at '/tmp/Rtmpz70sWH/dir181434dba423/file181454f7c22f'.
#> Unlocked file written at '/tmp/Rtmpz70sWH/dir181434dba423/file18145843c12d'.
#> Unlocked file written at '/tmp/Rtmpz70sWH/dir181434dba423/file18146a6098c2'.