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.
Usage
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
)
Arguments
- dir
A string indicating the directory to encrypt/decrypt. (default:
"./inst/extdata"
).- public_key
(optional) an
openssl
RSA public key or a string specifying the public key path. Seersa_keygen()
to learn how to create an RSA key pair (default:"./inst/ssh/id_rsa.pub"
).- suffix
(optional) a string specifying the suffix to be added (when encrypting)/removed (when decrypting) to/of the file. It must start with
.
(default:".lockr"
).- remove_file
(optional) a
logical
value indicating if the original file must be removed after the encryption/decryption process (default:TRUE
).- private_key
(optional) an
openssl
RSA private key or a string specifying the private key path. Seersa_keygen()
to learn how to create an RSA key pair (default:"./inst/ssh/id_rsa"
).- 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:
NULL
).
See also
Other lock/unlock functions:
lock_file()
Examples
## Locking files
ssh_dir <- tempfile("ssh")
dir.create(ssh_dir)
rsa_keygen(ssh_dir)
#> Keys successfully created at '/tmp/RtmpoFK8iT/ssh1d2e2c4b6368'.
temp_dir <- tempfile("dir")
dir.create(temp_dir)
for (i in seq(5)) {
file.create(tempfile(tmpdir = temp_dir))
}
list.files(temp_dir)
#> [1] "file1d2e20521a37" "file1d2e3154c9e7" "file1d2e46d7c588" "file1d2e572aae5f"
#> [5] "file1d2e66e179d6"
lock_dir(temp_dir, public_key = file.path(ssh_dir, "id_rsa.pub"))
#> Locked file written at
#> '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e20521a37.lockr'.
#> Locked file written at
#> '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e3154c9e7.lockr'.
#> Locked file written at
#> '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e46d7c588.lockr'.
#> Locked file written at
#> '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e572aae5f.lockr'.
#> Locked file written at
#> '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e66e179d6.lockr'.
## Unlocking files
unlock_dir(temp_dir, private_key = file.path(ssh_dir, "id_rsa"))
#> Unlocked file written at '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e20521a37'.
#> Unlocked file written at '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e3154c9e7'.
#> Unlocked file written at '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e46d7c588'.
#> Unlocked file written at '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e572aae5f'.
#> Unlocked file written at '/tmp/RtmpoFK8iT/dir1d2e430cb4d3/file1d2e66e179d6'.