---
title: "crypt.generatebytes"
description: "Generates secure random bytes and returns them Base64-encoded."
---

```lua
crypt.generatebytes(size: number): string
```

---

## Aliases

None.

---

## Arguments

<ParamField body="size" type="number" required>
  The number of random bytes before encoding. Converted to an integer, then checked against 0..1048576.
</ParamField>

---

## Returns

<ResponseField name="encoded" type="string">
  Base64 text containing the generated random bytes.
</ResponseField>

The size is converted to a native integer, then must be from 0 to 1048576 inclusive. Pass a whole-byte count; fractional input is truncated rather than explicitly rejected. Distinct from crypt.random, which returns raw bytes.

---

## Example

```lua
local encoded = crypt.generatebytes(16)
print(#crypt.base64decode(encoded))
```
