> 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/english/skyone-studio/how-to/encryption-hash-functions-in-jsonata-usdmd5-and-usdsha256.md).

# Encryption: Hash Functions in JSONata ($md5 and $sha256)

JSONata provides cryptographic hash functions that allow values to be transformed into unique and deterministic representations.

These functions can be used to:

* **Ensure data integrity**
* **Create unique identifiers**
* **Anonymize sensitive values**
* **Ensure compatibility with external systems**

### Supported functions:

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

### Difference Between MD5 and SHA-256

| Algorithm | Hash Size                | Security              | Common Usage                             |
| --------- | ------------------------ | --------------------- | ---------------------------------------- |
| MD5       | 32 characters (128 bits) | Weak, collision-prone | Checksums, simple validation             |
| SHA-256   | 64 characters (256 bits) | Strong, recommended   | Authentication, blockchain, cryptography |

### **Function `$md5(value)`**

* **Calculates the MD5 hash of the provided value.**
* **Return: fixed 32-character hexadecimal string**
* **Digest parameter: not supported**

**Example**

<pre><code><strong>Input:
</strong>{ "status": "200" }

Expression:
$md5(status)
</code></pre>

<figure><img src="https://2493694111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQPcfIOA6Tl2Bmk6CdV2O%2Fuploads%2FLJqJO17nymxI4Imph7Ad%2FGemini_Generated_Image_bvd2febvd2febvd2.png?alt=media&amp;token=afa9f4fb-a544-4591-85d7-cd941319efea" alt=""><figcaption></figcaption></figure>

```
Output:
{ "data": "3644a684f98ea8fe223c713b77189a77" }
```

<figure><img src="https://2493694111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQPcfIOA6Tl2Bmk6CdV2O%2Fuploads%2F0K6NkBjFoygOtS0Bff7K%2Fmd5Saida.png?alt=media&amp;token=42338fe7-440c-4a82-9703-d703819e641d" alt=""><figcaption></figcaption></figure>

### **Function `$sha256(value, digestFormat?)`**

* Calculates the SHA-256 hash of the provided value.
* Return: fixed 64-character hexadecimal string (by default)
* Digest parameter: supports `digestFormat` to change the output format

#### Supported formats (digestFormat)

| Value             | Description                  | Example Output             |
| ----------------- | ---------------------------- | -------------------------- |
| `"hex"` (default) | Hexadecimal representation   | `27badc983df1780b60c2...`  |
| `"base64"`        | Standard Base64              | `J7cmD3xeAtgwrP6nToZoA...` |
| `"base64url"`     | Base64 adapted for URLs/JWTs | `J7cmD3xeAtgwrP6nToZoA...` |

### Practical Examples

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

```
Input:
{ "status": "200" }

Expression:
$sha256(status)
```

<figure><img src="https://2493694111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQPcfIOA6Tl2Bmk6CdV2O%2Fuploads%2FgmJ5C6P3JPaOYDNVMPmu%2Fimage%20-%202025-09-16T132157.234.png?alt=media&amp;token=f6461ea2-3f00-42c7-bb15-890bd32c0ccd" alt=""><figcaption></figcaption></figure>

```
Output:
{ "data": "27badc983df1780b60c2b3fa9d3a19a00e46aac798451f0febdca52920faaddf" }
```

<figure><img src="https://2493694111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQPcfIOA6Tl2Bmk6CdV2O%2Fuploads%2FxzxgKDDaIKnRc4ANsGqz%2Fimage%20-%202025-09-16T132217.952.png?alt=media&amp;token=72779ee5-d3bc-4626-b839-e9322ffe6d41" alt=""><figcaption></figcaption></figure>

**SHA-256 in Base64**

```
Input:
{ "status": "200" }

Expression:
$sha256(status,"base64")
```

<figure><img src="https://2493694111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQPcfIOA6Tl2Bmk6CdV2O%2Fuploads%2F5mFErHMGyL7HoVOetyTF%2Fimage%20-%202025-09-16T132234.342.png?alt=media&amp;token=aa23c8df-c7f1-46da-9111-0dd93699c791" alt=""><figcaption></figcaption></figure>

```
Output:
{ "data": "J7cmD3xeAtgwrP6nToZoA5GqseYRR8P69y1KSD6rd8=" }
```

<figure><img src="https://2493694111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQPcfIOA6Tl2Bmk6CdV2O%2Fuploads%2FKDTH0f6uLsry98xUbrMz%2Fimage%20-%202025-09-16T132305.557.png?alt=media&amp;token=537af207-f51b-4edd-bea9-20e44ff1f237" alt=""><figcaption></figcaption></figure>

**SHA-256 in complex JSON (hex)**

```
Input:
{ "response": "{...JSON object...}" }

Expression:
$sha256(response)
```

<figure><img src="https://2493694111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQPcfIOA6Tl2Bmk6CdV2O%2Fuploads%2FSM8RqCYEVFRJ9dCpBSCq%2Funnamed%20(31).png?alt=media&amp;token=819145ac-ef5a-43db-a0bc-784586487009" alt=""><figcaption></figcaption></figure>

```
Output:
{ "data": "885826bd782b9b92cca593385729cc17ea05ca3f8f68935c5a1613102dfc066" }
```

<figure><img src="https://2493694111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQPcfIOA6Tl2Bmk6CdV2O%2Fuploads%2FArNRh744oYsILwg97gRO%2Funnamed%20(32).png?alt=media&amp;token=650ccbfe-c9f7-4cd3-97ac-99260ec1d201" alt=""><figcaption></figcaption></figure>

### Resumo dos tipos de digest

| Digest Format | Description                          |
| ------------- | ------------------------------------ |
| **hex**       | Hexadecimal representation (default) |
| **base64**    | Standard Base64 representation       |
| **base64url** | Base64 adapted for 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/english/skyone-studio/how-to/encryption-hash-functions-in-jsonata-usdmd5-and-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.
