crypt.decrypt
Decrypts AES-CBC data.
Syntax
Signature
crypt.decrypt(Data: string, Key: string, Iv: string, Mode: string?) -> stringAliases
This function has no aliases.
Parameters
| Parameter | Type | Description |
|---|---|---|
Data | string | Base64 ciphertext. |
Key | string | Base64 AES key. |
Iv | string | Base64 16-byte IV used during encryption. |
Mode | string? | Only the exact string CBC is supported. Defaults to CBC. |
Returns
| Type | Description |
|---|---|
string | Plaintext 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