decrypt_file {safer} | R Documentation |
Decrypt a file
Description
encrypt_file
) encrypts a file as a binary or a ascii
file. decrypt_file
) decrypts a text or a binary file (encrypted by
encrypt_file
)
Usage
decrypt_file(infile, key = "pass", pkey = NULL, ascii = FALSE, outfile)
Arguments
infile |
file to be decrypted |
key |
For symmetric decryption, 'pkey' should be NULL (default) and 'key' can be either a string (Default is 'pass') or a raw object. For asymmetric decryption, both 'key' (private key of the decrypter) and 'pkey' (public key of the encrypter) should be raw objects. |
pkey |
See 'key' |
ascii |
|
outfile |
Non-existant file where the decrypted output is to be written |
Value
An invisible TRUE
Examples
# symmetric case:
write.table(iris, "iris.csv")
all(
encrypt_file("iris.csv", outfile = "iris_encrypted.bin")
, file.exists("iris_encrypted.bin")
, decrypt_file("iris_encrypted.bin", outfile = "iris_2.csv")
, file.exists("iris_2.csv")
, tools::md5sum("iris_2.csv") == tools::md5sum("iris.csv")
, unlink("iris.csv") == 0
, unlink("iris_2.csv") == 0
, unlink("iris_encrypted.bin") == 0
)
write.table(iris, "iris.csv")
all(
encrypt_file("iris.csv", outfile = "iris_encrypted.txt", ascii = TRUE)
, file.exists("iris_encrypted.txt")
, decrypt_file("iris_encrypted.txt", outfile = "iris_2.csv", ascii = TRUE)
, file.exists("iris_2.csv")
, tools::md5sum("iris_2.csv") == tools::md5sum("iris.csv")
, unlink("iris.csv") == 0
, unlink("iris_2.csv") == 0
, unlink("iris_encrypted.txt") == 0
)
# asymmetric case:
alice <- keypair()
bob <- keypair()
write.table(iris, "iris.csv")
all(
encrypt_file("iris.csv", alice$private_key, bob$public_key, outfile = "iris_encrypted.bin")
, file.exists("iris_encrypted.bin")
, decrypt_file("iris_encrypted.bin", bob$private_key, alice$public_key, outfile = "iris_2.csv")
, file.exists("iris_2.csv")
, tools::md5sum("iris_2.csv") == tools::md5sum("iris.csv")
, unlink("iris.csv") == 0
, unlink("iris_2.csv") == 0
, unlink("iris_encrypted.bin") == 0
)
[Package safer version 0.2.1 Index]