Skip to contents

Phase 3JJJ1. Inverse of morie_crypto_chacha20_poly1305_encrypt(). Accepts the full ciphertext || tag buffer (concatenate as c(ct, tag)).

Usage

morie_crypto_chacha20_poly1305_decrypt(key, nonce, ct_with_tag, aad = raw(0))

Arguments

key

32-byte raw vector.

nonce

12-byte raw vector.

ct_with_tag

Raw vector containing ciphertext appended with the 16-byte tag.

aad

Optional raw vector of additional authenticated data.

Value

Decrypted plaintext as raw vector.

Examples

if (morie_crypto_sodium_available()) {
  k <- morie_crypto_random_bytes(32)
  n <- morie_crypto_random_bytes(12)
  pt <- charToRaw("the quick brown fox")
  aad <- charToRaw("hdr:v1")
  enc <- morie_crypto_chacha20_poly1305_encrypt(k, n, pt, aad)
  dec <- morie_crypto_chacha20_poly1305_decrypt(k, n, c(enc$ct, enc$tag), aad)
  identical(dec, pt)
}
#> [1] TRUE