> For the complete documentation index, see [llms.txt](https://docs.skyone.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.skyone.cloud/skyone-studio/how-to/criptografia-funcoes-de-hash-no-jsonata-usdmd5-e-usdsha256.md).

# Criptografia: Funções de Hash no JSONata ($md5 e $sha256)

O JSONata disponibiliza funções de hash criptográfico que permitem transformar valores em representações únicas e determinísticas.

Essas funções podem ser usadas para:

* **Garantir a integridade de dados**
* **Criar identificadores únicos**
* **Anonimizar valores sensíveis**
* **Garantir compatibilidade com sistemas externos**

### Funções suportadas:&#x20;

* `$md5(value)`
* `$sha256(value, digestFormat?)`

### Diferença entre MD5 e SHA-256

| Algoritmo | Tamanho do Hash          | Segurança                    | Uso Comum                              |
| --------- | ------------------------ | ---------------------------- | -------------------------------------- |
| MD5       | 32 caracteres (128 bits) | Fraca, suscetível a colisões | Checksums, validação simples           |
| SHA-256   | 64 caracteres (256 bits) | Forte, recomendado           | Autenticação, blockchain, criptografia |

### Função $md5(value)

* **Calcula o hash MD5 do valor fornecido.**
* **Retorno: string hexadecimal fixa de 32 caracteres.**
* **Não possui parâmetro de digest.**

#### Exemplo

<pre><code>Entrada:
<strong>{ "status": "200" }
</strong>
Expressão:
$md5(status)
</code></pre>

<figure><img src="/files/yoZNd6aoBpSdMLLBDqPr" alt=""><figcaption></figcaption></figure>

```
Saída:
{ "data": "3644a684f98ea8fe223c713b77189a77" }
```

<figure><img src="/files/ZdQv3UthfYATzwi6ixpO" alt=""><figcaption></figcaption></figure>

### Função $sha256(value, digestFormat?)

* Calcula o hash SHA-256 do valor fornecido.
* Retorno: string fixa de 64 caracteres em hexadecimal (por padrão).
* Suporta o parâmetro digestFormat para alterar o formato da saída.

#### Formatos suportados (digestFormat)

<table><thead><tr><th>Valor</th><th width="249">Descrição</th><th>Exemplo de saída</th></tr></thead><tbody><tr><td>"hex" (padrão)</td><td>Representação hexadecimal</td><td>27badc983df1780b60c2...</td></tr><tr><td>"base64"</td><td>Base64 padrão</td><td>J7cmD3xeAtgwrP6nToZoA...</td></tr><tr><td>"base64url"</td><td>Base64 adaptado para URLs/JWTs</td><td>J7cmD3xeAtgwrP6nToZoA...</td></tr></tbody></table>

### Exemplos práticos

**SHA-256 em hex (default)**

```
Entrada:
{ "status": "200" }

Expressão:
$sha256(status)
```

<figure><img src="/files/f1g5B2qkkdLpSSZzot1h" alt=""><figcaption></figcaption></figure>

```
Saída:
{ "data": "27badc983df1780b60c2b3fa9d3a19a00e46aac798451f0febdca52920faaddf" }
```

<figure><img src="/files/ZGYEMkIfQtc885c02GD0" alt=""><figcaption></figcaption></figure>

**SHA-256 em Base64**

```
Entrada:
{ "status": "200" }

Expressão:
$sha256(status,"base64")
```

<figure><img src="/files/z5JzIYSS43vNF1bFykUM" alt=""><figcaption></figcaption></figure>

```
Saída:
{ "data": "J7cmD3xeAtgwrP6nToZoA5GqseYRR8P69y1KSD6rd8=" }
```

<figure><img src="/files/0elHVEwgdiaHbtpqEYrC" alt=""><figcaption></figcaption></figure>

**SHA-256 em JSON complexo (hex)**

```
Entrada:
{ "response": "{...objeto JSON...}" }

Expressão:
$sha256(response)
```

<figure><img src="/files/vj0JHUqMIEouLaAgsIgL" alt=""><figcaption></figcaption></figure>

<pre><code><strong>Saída:
</strong>{ "data": "885826bd782b9b92cca593385729cc17ea05ca3f8f68935c5a1613102dfc066" }
</code></pre>

<figure><img src="/files/SuaTj9Mj5KO8b0bclu77" alt=""><figcaption></figcaption></figure>

### Resumo dos tipos de digest

| Descrição | Descrição                          |
| --------- | ---------------------------------- |
| hex       | Representação hexadecimal (padrão) |
| base64    | Representação em Base64 padrão     |
| base64url | Base64 adaptado para URLs/JWTs     |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.skyone.cloud/skyone-studio/how-to/criptografia-funcoes-de-hash-no-jsonata-usdmd5-e-usdsha256.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
