syn.crypt.encrypt Synchronous

  • syn.crypto.encrypt

Encrypt a byte string using the Synapse compatibility library’s local ciphertext format. Use it when both sides of a local data round trip use this compatibility format. Its output cannot be substituted for the separate ciphertext and IV returned by crypt.encrypt.

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

Parameters

Function parameters
ParameterTypeDescription
datastringPlaintext bytes to encrypt.
keystringRaw input key material used by this library to derive the encryption key.

Returns

string

A Base64 ciphertext envelope containing the nonce and encrypted data.

Usage notes

This uses a Kawaii-specific versioned format. Pass its output to syn.crypt.decrypt with the same key; it is a different format from crypt.encrypt.

Availability

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

Example

Example
Luau
-- Enable the Synapse environment setting before running this example.
local key = syn.crypt.random(32)
local ciphertext = syn.crypt.encrypt("example note", key)
print(syn.crypt.decrypt(ciphertext, key)) -- example note
Kawaii documentation