util.crypto.encrypt

Shared

Encrypts a string into a cryptographically encrypted string


Syntax

local result, iv = util.crypto.encrypt(
    mode,
    input,
    key
)

Parameters

TypeNameDescription
stringmodeEncryption mode
Refer Modes section
stringinputString containing data to encrypt
stringkeyKey to use for encryption

Returns

TypeNameDescription
string | boolresultEncrypted string on successful execution, false otherwise
string | nilivGenerated initialization vector on successful execution, or nil on failure

Modes

ModeDescription
"aes128"Advanced Encryption Standard 128-bit
"aes192"Advanced Encryption Standard 192-bit
"aes256"Advanced Encryption Standard 256-bit

Examples

Encrypts an input string
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)

On this page