> 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="https://2406186417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlGHvosl2xodpQaXzCzxY%2Fuploads%2F8A5xnvueppB4NhPnYk9q%2Fmd5Entrada.png?alt=media&amp;token=863397a9-3f5c-4ad8-9790-047c6b1e83d8" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2406186417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlGHvosl2xodpQaXzCzxY%2Fuploads%2F4cEiB3BFLH1oWosPq3hP%2Fmd5Saida.png?alt=media&amp;token=6860d67d-74ee-461d-bd73-f576d4f5fb91" 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="https://2406186417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlGHvosl2xodpQaXzCzxY%2Fuploads%2FJSYd1Ed8WfjBMVJTL2Nt%2Fsha256Entrada.png?alt=media&amp;token=bb5a6367-2a86-431a-bd1b-fc22667d210a" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2406186417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlGHvosl2xodpQaXzCzxY%2Fuploads%2FKCH3FqrgPPWCNnkwashq%2Fsha256Saida.png?alt=media&amp;token=8d90cb13-9b23-4384-94a8-97fb24381303" alt=""><figcaption></figcaption></figure>

**SHA-256 em Base64**

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

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

<figure><img src="https://2406186417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlGHvosl2xodpQaXzCzxY%2Fuploads%2FLij4QNp5NATI3pDLMyRx%2Fsha256Base64Entrada.png?alt=media&amp;token=1a7cd8d4-7298-4371-af24-50143e1d62e8" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2406186417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlGHvosl2xodpQaXzCzxY%2Fuploads%2F6dZgjeipAT9mCjEkIvfA%2Fsha256Base64Saida.png?alt=media&amp;token=88706eee-4f02-4d8e-99cb-5c6944b45ea0" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://2406186417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlGHvosl2xodpQaXzCzxY%2Fuploads%2FKLq5UnF8KTLgPynf6t36%2Funnamed%20(33).png?alt=media&amp;token=23921345-4a08-45ed-9540-6fe3b0217618" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2406186417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlGHvosl2xodpQaXzCzxY%2Fuploads%2FH95jI05KqDqGtG37AYyu%2Funnamed%20(34).png?alt=media&amp;token=3c632f1f-2488-41f8-960d-cca86dfbc2f8" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
