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
| Parameter | Type | Description |
|---|---|---|
plaintext | string | Raw bytes to encrypt. |
key | string | Base64-encoded key material. |
iv | string? | 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
exampleErrors: Invalid Base64 input raises an error.
