Syntax
crypt.generatekey(): stringReturns
| Name | Type | Description |
|---|---|---|
key | string | Base64 encoding of the generated 32 raw bytes. The returned string is not 32 characters long. |
Description
Generates 32 random raw bytes with random byte generator and returns them Base64-encoded as a Lua string.
Call it without parameters. The function reads the needed context from the current runtime state.
It returns key (string). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Generate a Base64 key and decode it to inspect the raw byte count.
local key = crypt.generatekey()
local raw = base64_decode(key)
local ciphertext, iv = crypt.encrypt("hello world", key)
print(key)
print(#raw)
print(ciphertext, iv)