Skip to main content

Arguments

string
required
Plaintext bytes read from a Lua string.
string
required
Base64 key decoded before it is passed to AES.
string
Optional Base64 IV for CBC or CTR. When omitted for CBC or CTR, a new AES block-size IV is generated.
"CBC" | "ECB" | "CTR" | "AES-CBC" | "AES-ECB" | "AES-CTR"
AES mode. The AES- prefix is removed when present. Defaults to AES-CBC. CBC and ECB use crypto library DEFAULT_PADDING; CTR uses no padding.

Returns

string
Base64-encoded ciphertext.
string | nil
Base64-encoded IV for CBC and CTR; nil for ECB.

Example

Encrypt a Lua string and decrypt the returned ciphertext with the returned IV.