safer (version 0.2.0)

decrypt_string: Decrypt a string

Description

encrypt_string encrypts a string as a string and decrypt_string decrypts the encrypted string(encrypted using encrypt_string)

Usage

decrypt_string(string, key = "pass", pkey = NULL)

Arguments

string

A string(character vector of length 1) without embedded NULL to be encrypted.

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'

Value

An encrypted string

Examples

Run this code
# NOT RUN {
# symmetric case:
temp <- encrypt_string("hello, how are you", key = "secret")
all(
  is.character(temp)
  , decrypt_string(temp, "secret") == "hello, how are you"
  , class(try(decrypt_string(temp, "nopass"), silent = TRUE)) == "try-error"
  )

# asymmetric case:
alice <- keypair()
bob   <- keypair()
temp  <- encrypt_string("hello asymmetric", alice$private_key, bob$public_key)
temp2 <- decrypt_string(temp, bob$private_key, alice$public_key)
identical("hello asymmetric", temp2)

# }

Run the code above in your browser using DataLab