# hash (Compartido)

> Calcula el hash de un texto: MD5, SHA-1, SHA-2 o un HMAC.

- **Plataforma**: MY Multiplayer (MYMP)
- **Tipo**: Función Lua
- **Lado**: Compartido
- **Categoría**: Datos y utilidades
- **URL**: https://wiki.mymp.gg/es/hash

## Sintaxis

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

## Parámetros

| Nombre | Tipo | Descripción |
| --- | --- | --- |
| `algorithm` | `string` | `"md5"`, `"sha1"`, `"sha224"`, `"sha256"`, `"sha384"`, `"sha512"` o `"hmac"`. |
| `data` | `string` | El texto. |
| `options` | `table` | Solo para `"hmac"`: `key` (la clave) y `algorithm` (uno de los otros algoritmos). *(por defecto: `nil`)* |

## Retorno

El hash en hexadecimal en minúsculas, o `false` si las opciones del HMAC no son válidas.

## Ejemplo

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

## Ver también

- [encodeString (Compartido)](https://wiki.mymp.gg/es/encodeString.md): Codifica o cifra un texto con un algoritmo: TEA, AES-128, RSA, Base64, Base32 o zlib.
- [decodeString (Compartido)](https://wiki.mymp.gg/es/decodeString.md): Decodifica o descifra un texto producido por encodeString.
