# hash (Compartilhado)

> Calcula o hash de um texto: MD5, SHA-1, SHA-2 ou um HMAC.

- **Plataforma**: MY Multiplayer (MYMP)
- **Tipo**: Função Lua
- **Lado**: Compartilhado
- **Categoria**: Dados e utilidades
- **URL**: https://wiki.mymp.gg/pt/hash

## Sintaxe

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

## Parâmetros

| Nome | Tipo | Descrição |
| --- | --- | --- |
| `algorithm` | `string` | `"md5"`, `"sha1"`, `"sha224"`, `"sha256"`, `"sha384"`, `"sha512"` ou `"hmac"`. |
| `data` | `string` | O texto. |
| `options` | `table` | Só para `"hmac"`: `key` (a chave) e `algorithm` (um dos outros algoritmos). *(padrão: `nil`)* |

## Retorno

O hash em hexadecimal minúsculo, ou `false` se as opções do HMAC são inválidas.

## Exemplo

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

## Veja também

- [encodeString (Compartilhado)](https://wiki.mymp.gg/pt/encodeString.md): Codifica ou cifra um texto com um algoritmo: TEA, AES-128, RSA, Base64, Base32 ou zlib.
- [decodeString (Compartilhado)](https://wiki.mymp.gg/pt/decodeString.md): Decodifica ou decifra um texto produzido por encodeString.
