# 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="/files/o8Fu25GhGtJVbFH3Jmds" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/dGQ8EVRrvRVAn2CXSok4" 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="/files/cnaSK1wPYNXOZRUDsT3H" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/1q6JfPiOWrcEtZMgBulN" alt=""><figcaption></figcaption></figure>

**SHA-256 in Base64**

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

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

<figure><img src="/files/8Nydt5SfX4l5OdhjXlpv" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/3bc9fKI0EI5RDxHGvE8U" alt=""><figcaption></figcaption></figure>

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

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

Expression:
$sha256(response)
```

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

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

<figure><img src="/files/SDaKrsfd8JQL3TAMs9R8" 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: 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:

```
GET https://docs.skyone.cloud/english/skyone-studio/how-to/encryption-hash-functions-in-jsonata-usdmd5-and-usdsha256.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
