crypt.decrypt
Decrypts data using a specified algorithm and key.
Syntax
crypt.decrypt(data: string, key: string, iv: string, mode?: string) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
data | string | Base64-encoded ciphertext returned by crypt.encrypt |
key | string | Base64-encoded 32-byte AES key |
iv | string | Base64-encoded IV returned by crypt.encrypt |
mode | string? | CBC, ECB, CTR, CFB, OFB, or GCM (default: CBC) |
Returns
| Type | Description |
|---|---|
string | The decrypted data |
Description
crypt.decrypt decrypts data returned by crypt.encrypt. The key, IV, and mode must match the encryption call. GCM verifies the appended authentication tag and raises an error if verification fails.
Example
local key = crypt.generatekey()
local original = "Hello, World!"
-- Encrypt and decrypt
local encrypted, iv = crypt.encrypt(original, key, nil, "CBC")
local decrypted = crypt.decrypt(encrypted, key, iv, "CBC")
print(decrypted) -- "Hello, World!"Related Functions
crypt.encrypt- Encrypt datacrypt.generatekey- Generate a key