> ## 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.hash

> Compute MD5, SHA and CRC32 hashes and HMAC signatures of strings.

`rb.hash` turns a string into a hash or checksum. A script reaches for it to
check that data has not changed, to build a cache key, or to sign a request
with a shared secret.

This script hashes a string, signs a message, and hashes bytes that are not
UTF-8:

```luau theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
-- rebind: min_sdk=3.9.0 name=example version=1.0.0
local message = "The quick brown fox jumps over the lazy dog"

print(rb.hash.sha256("abc"))
-- ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

print(rb.hash.hmac("sha256", "key", message))
-- f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8

print(type(rb.hash.crc32(message)))   -- number

-- bytes that are not UTF-8 go through hex first
print(rb.hash.md5(rb.codec.hex("\x00\xff")))
```

| Signature | Returns |
| - | - |
| `rb.hash.md5(data: string) -> string` | lowercase hex |
| `rb.hash.sha1(data: string) -> string` | lowercase hex |
| `rb.hash.sha256(data: string) -> string` | lowercase hex |
| `rb.hash.sha512(data: string) -> string` | lowercase hex |
| `rb.hash.crc32(data: string) -> number` | a number, not hex |
| `rb.hash.hmac(algo: string, key: string, data: string) -> string` | lowercase hex |

`algo` is `"sha256"`, `"sha512"` or `"sha1"`; anything else raises
`unknown HMAC algo: <algo>`.

`data`, and `key` for `hmac`, must be valid UTF-8; other bytes raise. To hash
binary data, hash `rb.codec.hex(data)` or `rb.codec.base64(data)` instead.


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