Encrypts data with AES-CBC (PKCS#7 padding).
The same (key, IV) pair must never be reused. Generate a random IV per message and transmit it alongside the ciphertext.
@eryx/crypto/aes ModuleAES (Advanced Encryption Standard) symmetric encryption.
Supports 128-, 192-, and 256-bit keys (determined by key length). Three operation modes are provided:
local aes = require("@eryx/crypto/aes")
local key = buffer.fromstring("0123456789abcdef") -- 16-byte AES-128
local iv = buffer.fromstring("0000000000000000")
local plain = buffer.fromstring("Hello, AES!")
local ct = aes.cbc_encrypt(key, iv, plain)
local pt = aes.cbc_decrypt(key, iv, ct)
assert(buffer.tostring(pt) == "Hello, AES!")
Encrypts data with AES-CBC (PKCS#7 padding).
The same (key, IV) pair must never be reused. Generate a random IV per message and transmit it alongside the ciphertext.
AES key - 16, 24, or 32 bytes (128/192/256-bit).
Initialisation vector - 16 bytes.
Plaintext to encrypt.
Ciphertext (length rounded up to a 16-byte block boundary).
Decrypts AES-CBC ciphertext (strips PKCS#7 padding).
AES key - 16, 24, or 32 bytes.
Initialisation vector - 16 bytes.
Ciphertext to decrypt.
Plaintext.
Encrypts data with AES-CTR (stream cipher; no padding).
CTR mode is length-preserving. The iv parameter is the 16-byte
counter block (typically a random nonce). A (key, IV) pair must
never be reused.
AES key - 16, 24, or 32 bytes.
Counter/nonce block - 16 bytes.
Plaintext to encrypt.
Ciphertext (same length as input).
Decrypts AES-CTR ciphertext.
CTR decryption is identical to encryption; this function is provided for API symmetry.
AES key - 16, 24, or 32 bytes.
Counter/nonce block - 16 bytes.
Ciphertext to decrypt.
Plaintext (same length as input).
Encrypts data with AES-GCM, returning the ciphertext and
authentication tag separately.
GCM provides authenticated encryption: the tag covers both the
ciphertext and any additional authenticated data (aad). A
(key, nonce) pair must never be reused; 12-byte random nonces are
standard.
local ct, tag = aes.gcm_encrypt(key, nonce, plain, aad)
local pt = aes.gcm_decrypt(key, nonce, ct, tag, aad)
AES key - 16, 24, or 32 bytes.
Nonce - 12 bytes recommended.
Plaintext to encrypt.
Additional authenticated data (not encrypted, but covered by tag).
Ciphertext.
16-byte authentication tag.
Decrypts AES-GCM ciphertext and verifies the authentication tag.
Raises an error if the tag does not match (i.e. the data has been tampered with or the wrong key/nonce/aad was supplied).
AES key - 16, 24, or 32 bytes.
Nonce - must match the value used during encryption.
Ciphertext.
16-byte authentication tag.
Additional authenticated data (must match encryption).
Plaintext.
Encrypts data with AES-CCM, returning the ciphertext and
authentication tag separately.
CCM is an AEAD mode similar to GCM but based on CBC-MAC. The nonce must be 7–13 bytes; shorter nonces allow larger messages.
AES key - 16, 24, or 32 bytes.
Nonce - 7 to 13 bytes.
Plaintext to encrypt.
Additional authenticated data.
Ciphertext.
Authentication tag.
Decrypts AES-CCM ciphertext and verifies the authentication tag.
Raises an error if the tag does not match.
AES key - 16, 24, or 32 bytes.
Nonce - must match the value used during encryption.
Ciphertext.
Authentication tag.
Additional authenticated data (must match encryption).
Plaintext.
Encrypts data with AES-ECB (PKCS#7 padding).
AES key - 16, 24, or 32 bytes.
Plaintext to encrypt.
Ciphertext (length rounded up to a 16-byte block boundary).
Decrypts AES-ECB ciphertext (strips PKCS#7 padding).
AES key - 16, 24, or 32 bytes.
Ciphertext to decrypt.
Plaintext.