syn. crypt. custom. encrypt Synchronous
syn.crypto.custom.encrypt
Encrypt bytes with a named cipher and key/IV bytes supplied by the caller. Use this when you need to match an existing cipher format rather than Kawaii’s default syn.crypt envelope.
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: AES needs 16, 24, or 32 bytes; Blowfish accepts 4 through 56 bytes. |
iv | string | Raw IV or nonce bytes. AES CBC/CFB/CTR/OFB need 16, Blowfish needs 8, and GCM needs a nonempty nonce. |
Returns
stringBase64 ciphertext. Save the cipher name and IV alongside it so the decrypt call can use the same settings.
Usage notes
Key and IV arguments are raw bytes, not Base64 strings. GCM and EAX authenticate their ciphertext; the other listed modes do not by themselves.
Availability
This function requires the Synapse environment setting, which is off by default.
Example
Luau
local key = "0123456789abcdef0123456789abcdef" -- 32 raw bytes
local iv = "0123456789abcdef" -- 16 raw bytes
local cipher = "aes-cbc"
local ciphertext = syn.crypt.custom.encrypt(cipher, "saved note", key, iv)
assert(syn.crypt.custom.decrypt(cipher, ciphertext, key, iv) == "saved note")