encrypt_data | R Documentation |
Encrypt and decrypt raw data, objects, strings and files. The
core functions here are encrypt_data
and
decrypt_data
which take raw data and decrypt it, writing
either to file or returning a raw vector. The other functions
encrypt and decrypt arbitrary R objects (encrypt_object
,
decrypt_object
), strings (encrypt_string
,
decrypt_string
) and files (encrypt_file
,
decrypt_file
).
encrypt_data(data, key, dest = NULL) encrypt_object(object, key, dest = NULL, rds_version = NULL) encrypt_string(string, key, dest = NULL) encrypt_file(path, key, dest = NULL) decrypt_data(data, key, dest = NULL) decrypt_object(data, key) decrypt_string(data, key) decrypt_file(path, key, dest = NULL)
data |
(for |
key |
A |
dest |
The destination filename for the encrypted or
decrypted data, or |
object |
(for |
rds_version |
RDS serialisation version to use (see
serialize. The default in R version 3.3 and below is version
2 - in the R 3.4 series version 3 was introduced and is becoming
the default. Version 3 format serialisation is not understood
by older versions so if you need to exchange data with older R
versions, you will need to use |
string |
(for |
path |
(for |
key <- key_sodium(sodium::keygen()) # Some super secret data we want to encrypt: x <- runif(10) # Convert the data into a raw vector: data <- serialize(x, NULL) data # Encrypt the data; without the key above we will never be able to # decrypt this. data_enc <- encrypt_data(data, key) data_enc # Our random numbers: unserialize(decrypt_data(data_enc, key)) # Same as the never-encrypted version: x # This can be achieved more easily using `encrypt_object`: data_enc <- encrypt_object(x, key) identical(decrypt_object(data_enc, key), x) # Encrypt strings easily: str_enc <- encrypt_string("secret message", key) str_enc decrypt_string(str_enc, key)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.