save_object encrypts a R object to raw or text connection
or a file. retrieve_object decrypts a raw or a text connection or a
file (encrypted by save_object). Note that retrieve_object
returns the object.
Arguments
- conn
A connection or a file where the decrypted content is written. If
asciiis TRUE, an decrypted text is written to the connection. Else, whenasciiis FALSE(default), a raw object is written to the connection- 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
TRUE, if the encrypted output is a string(written to the text connection). FALSE, if the encrypted output is a raw object(written to the raw connection)
Examples
# symmetric case:
all(
save_object(iris, conn = "iris_safer.bin")
, identical(retrieve_object(conn = "iris_safer.bin"), iris)
, unlink("iris_safer.bin") == 0
)
#> [1] TRUE
all(
save_object(iris, conn = "iris_safer_2.txt", ascii = TRUE)
, identical(retrieve_object(conn = "iris_safer_2.txt", ascii = TRUE), iris)
, unlink("iris_safer_2.txt") == 0
)
#> [1] TRUE
# asymmetric case:
alice <- keypair()
bob <- keypair()
all(
save_object(iris, alice$private_key, bob$public_key, conn = "iris_safer.bin")
, identical(retrieve_object(conn = "iris_safer.bin", bob$private_key, alice$public_key), iris)
, unlink("iris_safer.bin") == 0
)
#> [1] TRUE