Skip to content

crypto.encrypt

Encrypts data using a cipher algorithm, key, and optional initialization vector (IV).

Signature

luau
function encrypt(algorithm: CipherAlgorithm, data: string, key: string, iv: string?): string

Types

luau
type CipherAlgorithm = "aes-256-cbc" | "aes-256-gcm" | "aes-256-ctr"

Summary

Parameters

ParameterTypeDescription
algorithmCipherAlgorithmThe cipher algorithm to use.
datastringThe plain text data to encrypt.
keystringThe encryption key.
ivstring?The optional initialization vector.

Example

lua
local crypto = require("@runtime/crypto")

local encrypted = crypto.encrypt("aes-256-cbc", "Hello, World!", "my-32-byte-long-key-string!!!", "16-byte-iv-string")
print(encrypted)