Low-level symmetric encryption/decryption using the AES block cipher in CBC mode.
The key is a raw vector, for example a hash of some secret. When no shared
secret is available, a random key can be used which is exchanged via an
asymmetric protocol such as RSA. See rsa_encrypt() for a worked example
or encrypt_envelope() for a high-level wrapper combining AES and RSA.
Usage
aes_ctr_encrypt(data, key, iv = rand_bytes(16))
aes_ctr_decrypt(data, key, iv = attr(data, "iv"))
aes_cbc_encrypt(data, key, iv = rand_bytes(16))
aes_cbc_decrypt(data, key, iv = attr(data, "iv"))
aes_gcm_encrypt(data, key, iv = rand_bytes(12), aad = NULL)
aes_gcm_decrypt(
data,
key,
iv = attr(data, "iv"),
tag = attr(data, "tag"),
aad = NULL
)
aes_keygen(length = 16)Arguments
- data
raw vector or path to file with data to encrypt or decrypt
- key
raw vector of length 16, 24 or 32, e.g. the hash of a shared secret
- iv
raw vector of length 16 (aes block size) or NULL. The initialization vector is not secret but should be random
- aad
optional additional authenticated data for
aes_gcm: a raw vector or string that is authenticated by the tag but not encrypted. The same value must be supplied when decrypting.- tag
raw vector with the authentication tag for
aes_gcm, which is returned as an attribute byaes_gcm_encrypt. IfNULL, the data is not verified.- length
how many bytes to generate. Usually 16 (128-bit) or 12 (92-bit) for
aes_gcm