crypt.encrypt
Symmetric encryption. mode defaults to CBC.
Syntax
crypt.encrypt(data: string, key: string, iv?: string, mode?: string) -> string
Parameters
| Parameter | Type | Description |
|---|---|---|
data | string | The data payload to process or send. |
key | string | The key or secret used by the operation. |
iv? | string | The iv value used by the call. |
mode? | string | The cipher mode to use. |
Returns
| Type | Description |
|---|---|
string | The returned string. |
Description
crypt.encrypt is part of the Crypt library. Crypt functions process data locally. Keys, hashes and encrypted buffers remain inside the process.
The operation is performed immediately using the arguments supplied at the call site.
The aliases crypt.decrypt(data, key, iv, mode?) resolve to the same implementation.
Example
local key = crypt.generatekey(32)
local iv = crypt.generatebytes(16)
local encrypted = crypt.encrypt("secret", key, iv, "CBC")
print(crypt.decrypt(encrypted, key, iv, "CBC"))
Notes
- Aliases:
crypt.decrypt(data, key, iv, mode?). - Never log keys or decrypted buffers in production scripts.