syn.crypt.custom.encrypt Synchronous

  • syn.crypto.custom.encrypt

Encrypt bytes using an explicitly selected cipher and raw key material. Use it when the cipher and raw key format must be chosen explicitly. The example generates a fresh nonce for AES-GCM and retains it for decryption.

Syntax
Luau
syn.crypt.custom.encrypt(
    cipher: string,
    data: string,
    key: string,
    iv: string
) -> string

Parameters

Function parameters
ParameterTypeDescription
cipherstringCipher name: aes-cbc, aes-cfb, aes-ctr, aes-ofb, aes-gcm, aes-eax, bf-cbc, bf-cfb, or bf-ofb.
datastringPlaintext bytes.
keystringRaw key bytes: 16, 24, or 32 bytes for AES; 4–56 bytes for Blowfish.
ivstringRaw IV or nonce bytes. AES CBC/CFB/CTR/OFB use 16 bytes; Blowfish uses 8 bytes. GCM requires a nonempty nonce.

Returns

string

Base64 ciphertext.

Usage notes

Key and IV arguments contain raw bytes; they are not Base64-encoded inputs.

Availability

This function requires the Synapse environment setting, which is off by default.

Example

Example
Luau
-- Enable the Synapse environment setting first.
local key = syn.crypt.random(32)
local nonce = syn.crypt.random(12)
local ciphertext = syn.crypt.custom.encrypt("aes-gcm", "example note", key, nonce)
print(syn.crypt.custom.decrypt("aes-gcm", ciphertext, key, nonce))
Kawaii documentation