crypt.decrypt
Decrypts Base64 AES ciphertext with the original key, IV and mode.
Syntax
crypt.decrypt(data: string, key: string, iv: string, mode: string?) -> string
Parameters
| Parameter | Type | Description |
|---|---|---|
data | string | Base64 ciphertext from encrypt. |
key | string | Base64-encoded AES key. |
iv | string | Base64 IV from the encryption call. |
mode | string? | AES mode; defaults to CBC. |
Returns
| Type | Description |
|---|---|
string | Decrypted raw bytes. |
Description
The key must decode to 16, 24 or 32 bytes. Modes are CBC, ECB, CTR, CFB, OFB and GCM; CBC is the compatibility default. Pass the IV returned by encrypt. Wrong keys, invalid padding or failed GCM authentication raise errors. GCM uses a 12-byte generated IV and appends a 16-byte authentication tag before Base64 encoding. Other IV-based modes use the first 16 decoded IV bytes. Non-GCM modes do not authenticate the message.
Example
local key = crypt.generatekey()
local encrypted, iv = crypt.encrypt("hello", key, nil, "GCM")
print(crypt.decrypt(encrypted, key, iv, "GCM"))
These are Game executor contracts. Check build requirements and session lifetimes before using them.
