Syntax
crypt.encrypt(data: string, key: string, iv?: string, mode?: "CBC" | "ECB" | "CTR"): string | string | nilArguments
| Name | Type | Description |
|---|---|---|
data | string | Input byte string or text processed by the function. |
key | string | Cryptographic key used by the operation. |
iv? | string | Initialization vector used by the cipher. Provide it for decrypting existing data. |
mode? | "CBC" | "ECB" | "CTR" | AES mode. Defaults to CBC. |
Returns
| Name | Type | Description |
|---|---|---|
ciphertext | string | Encrypted text returned by the cipher. |
initializationVector | string | nil | Base64-encoded initialization vector for CBC and CTR; nil for ECB. |
Description
Encrypts a string with the provided key and returns the ciphertext together with the initialization vector used.
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 ciphertext (string), initializationVector (string | nil). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Example call with placeholder values.
local result = crypt.encrypt("example", "example", "example", nil)
print(result)