crypt. decrypt Synchronous
Decrypt AES ciphertext using its key, initialization vector, and cipher mode. Use it to recover data written by the matching encryption call. The key, mode, and IV must agree with encryption; catch errors when reading damaged or untrusted ciphertext.
Luau
crypt.decrypt(data: string, key: string, iv: string, mode: string?) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
data | string | Base64 ciphertext. The decoded ciphertext is limited to 16 MiB. |
key | string | Base64-encoded 32-byte key used for encryption. |
iv | string | Base64 initialization vector returned by encryption. |
mode | string? | AES mode: CBC, ECB, CTR, CFB, OFB, or GCM. Defaults to CBC; names are case insensitive. |
Returns
stringThe plaintext bytes.
Usage notes
Keys decode to exactly 32 bytes. CBC, CTR, CFB, and OFB use a 16-byte IV; a 32-byte IV is truncated for compatibility. GCM generates a 12-byte IV and accepts supplied IVs of at least 12 bytes. ECB ignores the IV.
Use the same mode for encryption and decryption. Ciphertext and IV are Base64 strings; plaintext is raw bytes.
Example
Luau
local key = crypt.generatekey()
local encrypted, iv = crypt.encrypt("private example note", key, nil, "GCM")
local restored = crypt.decrypt(encrypted, key, iv, "GCM")
print(restored) -- private example note