# hash (Shared)

> Hashes a text: MD5, SHA-1, SHA-2 or an HMAC.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Data and utilities
- **URL**: https://wiki.mymp.gg/en/hash

## Syntax

```lua
string|false hash(string algorithm, string data [, table options = nil])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `algorithm` | `string` | `"md5"`, `"sha1"`, `"sha224"`, `"sha256"`, `"sha384"`, `"sha512"` or `"hmac"`. |
| `data` | `string` | The text. |
| `options` | `table` | Only for `"hmac"`: `key` (the key) and `algorithm` (one of the other algorithms). *(default: `nil`)* |

## Returns

The hash in lowercase hex, or `false` if the HMAC options are invalid.

## Example

```lua
local digest = hash("sha256", "hello")
local signature = hash("hmac", "payload", { key = "secret", algorithm = "sha256" })
```

## See also

- [encodeString (Shared)](https://wiki.mymp.gg/en/encodeString.md): Encodes or encrypts a text with an algorithm: TEA, AES-128, RSA, Base64, Base32 or zlib.
- [decodeString (Shared)](https://wiki.mymp.gg/en/decodeString.md): Decodes or decrypts a text encodeString produced.
