PKI (version 0.1-3)

PKI.crypt: PKI encryption/decryption functions

Description

PKI.encrypt encrypts a raw vector

PKI.decrypt decrypts a raw vector

Usage

PKI.encrypt(what, key, cipher = NULL) PKI.decrypt(what, key, cipher = NULL)

Arguments

what
raw vector to encrypt/decrypt. It must not exceed the key size minus padding
key
key to use for encryption/decryption
cipher
cipher to use for encryption/decryption

Value

Raw vector (encrypted/decrypted)

See Also

PKI.genRSAkey, PKI.pubkey

Examples

Run this code
  key <- PKI.genRSAkey(2048)
  x <- charToRaw("Hello, world!")
  e <- PKI.encrypt(x, key)
  y <- PKI.decrypt(e, key)
  stopifnot(identical(x, y))
  print(rawToChar(y))

  ## AES symmetric - use SHA256 to support arbitrarily long key strings
  key <- PKI.digest(charToRaw("hello"), "SHA256")
  ae <- PKI.encrypt(x, key, "aes256")
  ae
  ad <- PKI.decrypt(ae, key, "aes256")
  stopifnot(identical(x, ad))

Run the code above in your browser using DataLab