> ## Documentation Index
> Fetch the complete documentation index at: https://docsuncv2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# crypt.base64encode

Encodes `data` into a Base64 string.

```luau theme={null}
crypt.base64encode(data: string): string
```

Base64 turns any data - even bytes that aren't normal text - into plain text characters. That lets it go through JSON, a remote, or a file without breaking. The result is about a third bigger than the input.

Most commonly used to make a binary payload safe to send over `request` or store with `writefile`.

## Parameters

| Parameter | Type     | Description          |
| --------- | -------- | -------------------- |
| `data`    | `string` | The bytes to encode. |

## Returns

`string` - the Base64-encoded text.

## Aliases

* `base64.encode`
* `base64_encode`
* `base64encode`
* `crypt.base64.encode`
* `crypt.base64_encode`

## Example

Encode a value with Base64, then cache it to disk with `writefile`.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  local base64encode = crypt.base64encode("Hello, world!")
  =======
  -- crypt.base64encode(data: string): string
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local blob = crypt.base64encode("Hello, world!")
  print(blob) --> "SGVsbG8sIHdvcmxkIQ=="

  writefile("config.cache", blob)
  ```
</CodeGroup>

<Tip>
  Useful for encoding binary payloads before saving or transmission.
</Tip>
