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.
Luau
syn.crypt.custom.encrypt(
cipher: string,
data: string,
key: string,
iv: string
) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
cipher | string | Cipher name: aes-cbc, aes-cfb, aes-ctr, aes-ofb, aes-gcm, aes-eax, bf-cbc, bf-cfb, or bf-ofb. |
data | string | Plaintext bytes. |
key | string | Raw key bytes: 16, 24, or 32 bytes for AES; 4–56 bytes for Blowfish. |
iv | string | Raw IV or nonce bytes. AES CBC/CFB/CTR/OFB use 16 bytes; Blowfish uses 8 bytes. GCM requires a nonempty nonce. |
Returns
stringBase64 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
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))