
ChaCha20-Poly1305 IETF authenticated decryption
Source:R/crypto_sym.R
morie_crypto_chacha20_poly1305_decrypt.RdPhase 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))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