Cryptography

crypt.decrypt

Decrypts ciphertext with the provided key, initialization vector, and optional cipher mode.

Syntax

crypt.decrypt(data: string, key: string, iv: string, mode?: "CBC" | "ECB" | "CTR"): string

Arguments

NameTypeDescription
datastringInput byte string or text processed by the function.
keystringCryptographic key used by the operation.
ivstringInitialization vector used by the cipher. Provide it for decrypting existing data.
mode?"CBC" | "ECB" | "CTR"AES mode. Defaults to CBC.

Returns

NameTypeDescription
plaintextstringDecrypted plain text.

Description

Decrypts ciphertext with the provided key, initialization vector, and optional cipher mode.

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

Example call with placeholder values.

local result = crypt.decrypt("example", "example", "example", nil)
print(result)