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

Hashes a string with the named algorithm and returns the digest as a hex string.

```luau theme={null}
crypt.hash(data: string, algorithm: string): string
```

Accepted algorithms:

* `"md5"` - 32-character digest
* `"sha1"` - 40-character digest
* `"sha256"` - 64-character digest
* `"sha384"` - 96-character digest
* `"sha512"` - 128-character digest
* `"sha3-256"` - 64-character digest
* `"sha3-512"` - 128-character digest

Most commonly used to compare two large strings fastly - hash both and compare them, instead of running a byte-by-byte equality.

## Parameters

| Parameter   | Type     | Description                                              |
| ----------- | -------- | -------------------------------------------------------- |
| `data`      | `string` | The content to hash.                                     |
| `algorithm` | `string` | One of the algorithm names listed above. Case-sensitive. |

## Returns

`string` - the hex digest. Length depends on the algorithm (see list above).

## Example

Detect whether an <abbr title="The original source you downloaded the file from.">upstream</abbr> file has changed since you last cached it.

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

  ```luau Example 2 theme={null}
  local cachedHash = crypt.hash(readfile("cache/payload.bin"), "sha256")
  local freshHash  = crypt.hash(game:HttpGet("https://example.com/payload.bin"), "sha256")

  if cachedHash == freshHash then
      print("didn't change - keep the cache")
  else
      print("changed - refresh the cache")
  end
  ```
</CodeGroup>

<Tip>
  Commonly supported algorithms include `'sha1'`, `'sha256'`, `'sha512'`, `'md5'`.
</Tip>
