crypt.generatebytes Synchronous

Make random bytes and receive them as printable Base64. This is handy for a random token that must travel through a text field without an extra encoding step.

Syntax
Luau
crypt.generatebytes(length: number) -> string

Parameters

Function parameters
ParameterTypeDescription
lengthnumberNumber of random bytes before encoding, an integer from 0 through 512.

Returns

string

Base64 text. Its character count will usually exceed the requested byte count.

Usage notes

The length argument counts raw bytes, not characters in the result. Use crypt.random when the consumer expects raw bytes instead.

Example

Example
Luau
local token = crypt.generatebytes(16)
print(token)
assert(#base64decode(token) == 16)
Kawaii documentation