AcediaDocumentation

crypt.encrypt

Encrypts bytes using AES-256-CBC with PKCS#7 padding.

Returns Base64 ciphertext and Base64 IV. The current implementation folds decoded key/IV material into 32/16 bytes using XOR; prefer an exact 32-byte key and 16-byte IV. CBC encryption does not include an authentication tag.

crypt.encrypt(plaintext: string, key: string, iv: string?): (string, string)

Parameters

ParameterTypeDescription
plaintextstringRaw bytes to encrypt.
keystringBase64-encoded key material.
ivstring?Base64 IV material; omitted or empty generates a random IV.

Example

local key = crypt.generatekey()
local ciphertext, iv = crypt.encrypt("example", key)
print(crypt.decrypt(ciphertext, key, iv))

Example output

example

Errors: Invalid Base64 input raises an error.

On this page