ReferenceEncoding and crypto

crypt.generatebytes

Generates cryptographically random bytes and returns them as Base64 text.

Syntax

crypt.generatebytes(length: number) -> string

Parameters

ParameterTypeDescription
lengthnumberNumber of random bytes, from 0 through 512.

Returns

TypeDescription
stringBase64-encoded random bytes.

Description

Length counts random bytes before any encoding, not characters in the returned string. It must be an integer from 0 through 512. Decode the result when an API expects raw bytes. Use crypt.generatekey for a ready-made AES-256 key.

Example

local value = crypt.generatebytes(16)
print(#value)

These are Game executor contracts. Check build requirements and session lifetimes before using them.