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

# rb.codec

> Encode bytes as Base64 or hex text and decode them back.

`rb.codec` turns any bytes into Base64 or lowercase hex text and back. A script
reaches for it to pass binary data to a call that takes only valid UTF-8, such
as [`rb.hash`](https://docs.rebind.gg/reference/sdk/hash). These are encodings, not encryption.

This script round-trips text through Base64, binary bytes through hex, and
catches a decode error:

```luau theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
-- rebind: min_sdk=3.9.0 name=example version=1.0.0
local encoded = rb.codec.base64("hello world")
rb.log.info(encoded)                          -- aGVsbG8gd29ybGQ=
rb.log.info(rb.codec.base64_decode(encoded))  -- hello world

local bytes = "\0\255"
rb.log.info(rb.codec.hex(bytes))              -- 00ff
assert(rb.codec.hex_decode("00ff") == bytes)

local ok, err = pcall(rb.codec.hex_decode, "zz")
if not ok then
  rb.log.warn(tostring(err))
end
```

| Signature | Returns |
| - | - |
| `rb.codec.base64(data: string) -> string` | Base64 of any bytes |
| `rb.codec.base64_decode(str: string) -> string` | bytes; raises `base64 decode error: <reason>` |
| `rb.codec.hex(data: string) -> string` | lowercase hex of any bytes |
| `rb.codec.hex_decode(str: string) -> string` | bytes; raises `hex decode error: <reason>` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.