ReferenceEncoding and crypto

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

ParameterTypeDescription
datastringBase64 ciphertext from encrypt.
keystringBase64-encoded AES key.
ivstringBase64 IV from the encryption call.
modestring?AES mode; defaults to CBC.

Returns

TypeDescription
stringDecrypted 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.