Vital.sandbox
Crypto

crypto.encrypt

Shared

Encrypts a string into a cryptographically encrypted string


Syntax

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

Parameters

TypeNameDescription
stringmodeEncryption mode:
"AES128" - Advanced Encryption Standard 128-bit
"AES192" - Advanced Encryption Standard 192-bit
"AES256" - Advanced Encryption Standard 256-bit
stringinputString containing data to be encrypted
stringkeyKey to be used for encryption

Returns

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

Examples

local input = "Hello World"
local key = "MySecretKey12345"
local output, iv = crypto.encrypt("AES256", input, key)

engine.print("Input:", input)
engine.print("Encrypted:", output, "IV:", iv)

On this page