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.
Luau
crypt.generatebytes(length: number) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
length | number | Number of random bytes before encoding, an integer from 0 through 512. |
Returns
stringBase64 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
Luau
local token = crypt.generatebytes(16)
print(token)
assert(#base64decode(token) == 16)