crypt.generatekey Synchronous

Generate a random 32-byte key for the crypt library. Use it to create a key in the format crypt.encrypt expects. Generate it once for the data you intend to decrypt later; generating a new key cannot recover old ciphertext.

Syntax
Luau
crypt.generatekey() -> string

Parameters

This function takes no arguments.

Returns

string

A Base64-encoded key string accepted by crypt.encrypt and crypt.decrypt.

Example

Example
Luau
local key = crypt.generatekey()
local encrypted, iv = crypt.encrypt("private example note", key, nil, "GCM")
local restored = crypt.decrypt(encrypted, key, iv, "GCM")
print(restored) -- private example note
Kawaii documentation