Volt

crypt.encrypt

Encrypts data using a specified algorithm and key.

Syntax

crypt.encrypt(data: string, key: string, iv: string?, algorithm: string?) -> string

Parameters

ParameterTypeDescription
datastringThe data to encrypt
keystringThe encryption key
ivstring(Optional) Initialization vector
algorithmstring(Optional) Algorithm, defaults to "AES-CBC"

Returns

TypeDescription
stringThe encrypted data

Description

crypt.encrypt encrypts the provided data using the specified algorithm and key. The result is typically Base64-encoded.

Supported Algorithms

  • AES-CBC (default)
  • AES-GCM
  • AES-CTR

Example

local key = crypt.generatekey()
local data = "Secret message"

-- Encrypt with default algorithm
local encrypted = crypt.encrypt(data, key)
print("Encrypted:", encrypted)

-- Decrypt to verify
local decrypted = crypt.decrypt(encrypted, key)
print("Decrypted:", decrypted)

With Custom IV

local key = crypt.generatekey()
local iv = crypt.generatebytes(16)
local data = "Secret message"

local encrypted = crypt.encrypt(data, key, iv, "AES-CBC")
local decrypted = crypt.decrypt(encrypted, key, iv, "AES-CBC")

On this page