safer (version 0.2.0)

encrypt_object: Encrypt a object

Description

encrypt_object encrypts a object as a raw object or a string and decrypt_object decrypts a raw object or a string(encrypted by encrypt_object)

Usage

encrypt_object(object, key = "pass", pkey = NULL, ascii = FALSE)

Arguments

object

Object to be encrypted

key

For symmetric encryption, 'pkey' should be NULL (default) and 'key' can be either a string (Default is 'pass') or a raw object. For asymmetric encryption, both 'key' (private key of the encrypter) and 'pkey' (public key of the decrypter) should be raw objects.

pkey

See 'key'

ascii

TRUE if the object is to be encrypted as a string. Default is FALSE

Value

A raw object if ascii is FALSE. A string if ascii is TRUE.

Examples

Run this code
# NOT RUN {
# symmetric case:
temp <- encrypt_object(1:3)
all(
  is.raw(temp)
  , decrypt_object(temp) == 1:3)

temp <- encrypt_object(iris, ascii = TRUE)
all(
  is.character(temp)
  , decrypt_object(temp) == iris
  , identical(decrypt_object(temp), iris))
rm(temp)

# asymmetric case:
alice <- keypair()
bob   <- keypair()
temp  <- encrypt_object(1:10, alice$private_key, bob$public_key)
temp2 <- decrypt_object(temp, bob$private_key, alice$public_key)
identical(1:10, temp2)

# }

Run the code above in your browser using DataCamp Workspace