WARNING: Use this function with caution! Check the parameters carefully.
lock_dir() and unlock_dir() encrypt or decrypt all files from a given
directory using an OpenSSL RSA key pair.
Arguments
- dir
A
characterstring indicating the directory to encrypt or decrypt.- public_key
(optional) An
opensslRSA public key or acharacterstring specifying the public key path. Seersa_keygen()to learn how to create an RSA key pair (default:here::here("_ssh", "id_rsa.pub")).- suffix
(optional) A
characterstring specifying the suffix to add when encrypting or remove when decrypting. Must start with.(default:".lockr").- remove_file
(optional) A
logicalvalue indicating if the original file must be removed after the encryption/decryption process (default:TRUE).- private_key
(optional) An
opensslRSA private key or acharacterstring specifying the private key path. Seersa_keygen()to learn how to create an RSA key pair (default:here::here("_ssh", "id_rsa")).- password
(optional) A
characterstring specifying the password for decrypting a protected private key. For security, avoid hardcoding passwords in scripts. Useaskpass()to prompt for secure input (default:NULL).
Value
An invisible NULL. These functions are called
for side effects only.
See also
Other lock/unlock functions:
lock_file(),
save_and_lock()
Examples
## Locking files -----
ssh_dir <- tempfile("ssh")
dir.create(ssh_dir)
rsa_keygen(ssh_dir)
#> ℹ Keys successfully created at /tmp/Rtmpu67Iup/ssh19f64f18f216.
temp_dir <- tempfile("dir")
dir.create(temp_dir)
for (i in seq_len(5)) file.create(tempfile(tmpdir = temp_dir))
list.files(temp_dir)
#> [1] "file19f612e48730" "file19f625d46003" "file19f62e93c8f8" "file19f665db8d77"
#> [5] "file19f67d620525"
temp_dir |>
lock_dir(
public_key = file.path(ssh_dir, "id_rsa.pub")
)
#> ℹ Locked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f612e48730.lockr.
#> ℹ Locked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f625d46003.lockr.
#> ℹ Locked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f62e93c8f8.lockr.
#> ℹ Locked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f665db8d77.lockr.
#> ℹ Locked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f67d620525.lockr.
## Unlocking files -----
temp_dir |>
unlock_dir(
private_key = file.path(ssh_dir, "id_rsa")
)
#> ℹ Unlocked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f612e48730.
#> ℹ Unlocked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f625d46003.
#> ℹ Unlocked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f62e93c8f8.
#> ℹ Unlocked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f665db8d77.
#> ℹ Unlocked file written at /tmp/Rtmpu67Iup/dir19f659a1a2f1/file19f67d620525.