Syntax
crypt.generatebytes(size: number): stringArguments
| Name | Type | Description |
|---|---|---|
size | number | Number converted to an integer before allocation. Values less than or equal to 0 are changed to 1. |
Returns
| Name | Type | Description |
|---|---|---|
encoded | string | Base64 encoding of the generated raw bytes. The returned string length is not the requested byte count. |
Description
Generates random bytes with random byte generator and returns them Base64-encoded as a Lua string.
Call it with 1 parameter(s): size. The argument table explains which values are required and which ones only refine the behavior.
It returns encoded (string). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Generate bytes and decode the Base64 result when raw bytes are needed.
local encoded = crypt.generatebytes(16)
local raw = base64_decode(encoded)
print(encoded)
print(#encoded)
print(#raw)