util.crypto.encrypt
Shared
Encrypts a string into a cryptographically encrypted string
Syntax
local result, iv = util.crypto.encrypt(
mode,
input,
key
)Parameters
| Type | Name | Description |
|---|---|---|
string | mode | Encryption mode Refer Modes section |
string | input | String containing data to encrypt |
string | key | Key to use for encryption |
Returns
| Type | Name | Description |
|---|---|---|
string | bool | result | Encrypted string on successful execution, false otherwise |
string | nil | iv | Generated initialization vector on successful execution, or nil on failure |
Modes
| Mode | Description |
|---|---|
"aes128" | Advanced Encryption Standard 128-bit |
"aes192" | Advanced Encryption Standard 192-bit |
"aes256" | Advanced Encryption Standard 256-bit |
Examples
local input = "Hello World"
local key = "MySecretKey12345"
local output, iv = util.crypto.encrypt("aes256", input, key)
core.engine.print("info", "Input:", input)
core.engine.print("info", "Encrypted:", output, "IV:", iv)