Skip to content
Encoding & cryptographyReference

crypt.decrypt

Decrypt Base64-encoded AES-256-CBC data.

Details#

Decrypt Base64-encoded AES-256-CBC data. Raw plaintext bytes. Invalid Base64, key, IV, mode or padding/decryption failure raises an error.

Signature#

Luau
crypt.decrypt(data: string, key: string, iv: string, mode: string?): string

Parameters#

ParameterTypeDescription
datastringBase64 ciphertext produced by encrypt.
keystringBase64 encoding of the same 32-byte key.
ivstringBase64 IV with at least 16 decoded bytes; first 16 are used.
modeoptionalstringCBC only; default CBC, case-insensitive.

Returns#

Raw plaintext bytes. Invalid Base64, key, IV, mode or padding/decryption failure raises an error.

Examples#

Local example

Luau
local key = crypt.generatekey()
local data, iv = crypt.encrypt("Saved locally", key)
print(crypt.decrypt(data, key, iv)) -- Saved locally