crypt.decrypt

Decrypts AES-CBC data.

Syntax

Signature
crypt.decrypt(Data: string, Key: string, Iv: string, Mode: string?) -> string

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
DatastringBase64 ciphertext.
KeystringBase64 AES key.
IvstringBase64 16-byte IV used during encryption.
Modestring?Only the exact string CBC is supported. Defaults to CBC.

Returns

TypeDescription
stringPlaintext bytes.

Notes

Key must decode from Base64 to 16, 24, or 32 bytes and Iv must decode to 16 bytes. The IV is required. Invalid sizes, mode, or padding raise errors. A successful decode does not prove the ciphertext is authentic.

Example

Luau
local Key = crypt.generatekey()
local Ciphertext, Iv = crypt.encrypt("A message", Key)

local Ok, Plaintext = pcall(crypt.decrypt, Ciphertext, Key, Iv)
if Ok then
    print(Plaintext)
else
    warn("Decryption failed:", Plaintext)
end