Skip to content
Saiko

crypt.encrypt

Encrypts a string with AES and returns the result as base64.

Signature

luau
crypt.encrypt(data: string, key: string, iv: string, mode: string): string

Parameters

datastring

The plain text to encrypt.

keystring

The key, base64 encoded. A key made by crypt.generatekey has the right size.

ivstring

The initialization vector, base64 encoded, 16 bytes before encoding.

modestring

The cipher mode. "CBC" is the one the Myriad checks use.

Returns

string

Note

Example

luau
local key = crypt.generatekey()
local iv = crypt.generatebytes(16)

local encrypted = crypt.encrypt("hello world", key, iv, "CBC")
print(encrypted) --> base64 text
print(crypt.decrypt(encrypted, key, iv, "CBC")) --> hello world