# getHash

## `getHash` Function

The `getHash` function generates a **hashed string** from a given input using the [Node.js `crypto`](https://nodejs.org/api/crypto.html#cryptocreatehashalgorithm-options) library. It supports configurable **hashing algorithms** and **output encodings**.

***

### Purpose

Use this function to:

* Create hashed versions of identifiers or tokens
* Generate consistent anonymized values (e.g., hashed IPs, emails)
* Integrate hash-based logic into tracking or enrichment flows

***

### Function Definition

| Property          | Description                              |
| ----------------- | ---------------------------------------- |
| **Function Name** | `this.getHash`                           |
| **Type**          | `function`                               |
| **Available In**  | Server-Side Variables                    |
| **Returns**       | `string` (the hashed value of the input) |

***

### Parameters

| Parameter   | Description                                                    | Type     | Required                                      | Example    |
| ----------- | -------------------------------------------------------------- | -------- | --------------------------------------------- | ---------- |
| `input`     | The input string to be hashed                                  | `string` | <i class="fa-square-check">:square-check:</i> | `"secret"` |
| `algorithm` | The hashing algorithm to use (e.g., `"sha256"`, `"md5"`, etc.) | `string` | <i class="fa-square-check">:square-check:</i> | `"sha256"` |
| `encoding`  | The output format of the hash (`"hex"`, `"base64"`, etc.)      | `string` |                                               | `"hex"`    |

> **Default Encoding:** `"hex"` if not specified

***

### Supported Algorithms & Encodings

See the official [Node.js Crypto documentation](https://nodejs.org/api/crypto.html#cryptocreatehashalgorithm-options) for a full list of supported algorithms and encodings.

Common choices:

* **Algorithms:** `sha256`, `sha1`, `md5`, `sha512`
* **Encodings:** `hex`, `base64`, `latin1`

***

### Example Usage

```js
async function() {
    let x = this.getHash("secret", "sha256", "hex");
    return x;
}
```

This example returns a SHA-256 hash of the string `"secret"` encoded in hexadecimal.

***

### Use Cases

* Generate anonymized keys (e.g., hashed IP or user ID)
* Create checksum or verification values
* Store secure reference identifiers without exposing raw input
* Match identifiers across systems using shared hashing rules

***

### Notes

* This function uses Node.js' built-in `crypto.createHash` behind the scenes.
* Output is deterministic: same input → same hash.
* Make sure the chosen algorithm and encoding match your system requirements.
* Do **not** use `md5` or `sha1` for security-critical applications — these are considered weak.

***

### Summary

`this.getHash` is a flexible and secure way to generate hashed values in JENTIS server-side variables. Whether you’re anonymizing personal data or aligning IDs across systems, this function allows full control over the hashing algorithm and encoding.


---

# 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.jentis.com/developer-guide/variables/server-side-variables/public-function-scope/gethash.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.
