Syntax
crypt.decrypt(data: string, key: string, iv: string, mode?: "CBC" | "ECB" | "AES-CBC" | "AES-ECB"): stringArguments
| Name | Type | Description |
|---|---|---|
data | string | Base64 ciphertext decoded before decryption. |
key | string | Base64 key decoded before it is passed to AES. |
iv | string | Base64 IV decoded before mode handling. This argument is required, including for ECB. |
mode? | "CBC" | "ECB" | "AES-CBC" | "AES-ECB" | AES mode. The AES- prefix is removed when present. Defaults to AES-CBC. |
Returns
| Name | Type | Description |
|---|---|---|
plaintext | string | Plaintext bytes returned as a Lua string. |
Description
Decrypts Base64 ciphertext with a Base64-decoded key and required Base64 IV using AES CBC or ECB.
Call it with 4 parameter(s): data, key, iv, mode. The argument table explains which values are required and which ones only refine the behavior.
It returns plaintext (string). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Decrypt ciphertext returned by crypt.encrypt using the returned IV.
local key = crypt.generatekey()
local ciphertext, iv = crypt.encrypt("hello world", key)
local plaintext = crypt.decrypt(ciphertext, key, iv)
print(plaintext)