crypt.generatekey Synchronous

Generate a fresh AES key in the exact format crypt.encrypt expects. Keep this value if you need to decrypt the resulting ciphertext after the script ends.

Syntax
Luau
crypt.generatekey() -> string

Parameters

This function takes no arguments.

Returns

string

A Base64-encoded 32-byte key string.

Usage notes

Calling it again creates a different key; it does not retrieve an earlier one.

Example

Example
Luau
local key = crypt.generatekey()
local ciphertext, iv = crypt.encrypt("saved value", key, nil, "GCM")
print(#key, #ciphertext, #iv)
assert(crypt.decrypt(ciphertext, key, iv, "GCM") == "saved value")
Kawaii documentation