> For the complete documentation index, see [llms.txt](https://docs.jentis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jentis.com/developer-guide/variables/server-side-variables/public-function-scope/gethmacsha1.md).

# getHmacSHA1

## `getHmacSHA1` Function

The `getHmacSHA1` function returns a **SHA-1 HMAC (Hash-based Message Authentication Code)** from an input string using Node.js’ built-in [`crypto`](https://nodejs.org/api/crypto.html#cryptocreatehmacalgorithm-key-options) module. This function is commonly used for **signed payloads, request validation, or secure token generation**.

***

### Purpose

Use this function to:

* Generate **signed hashes** with a secret key (HMAC)
* Verify payload integrity between systems
* Implement token-based authentication or validation
* Create secure webhooks or API signature mechanisms

***

### Function Definition

| Property          | Description                        |
| ----------------- | ---------------------------------- |
| **Function Name** | `this.getHmacSHA1`                 |
| **Type**          | `function`                         |
| **Available In**  | Server-Side Variables              |
| **Returns**       | `string` (SHA-1 HMAC of the input) |

***

### Parameters

| Parameter    | Description                                                       | Type     | Required                                      | Example           |
| ------------ | ----------------------------------------------------------------- | -------- | --------------------------------------------- | ----------------- |
| `secret-key` | The secret used to sign the HMAC                                  | `string` | <i class="fa-square-check">:square-check:</i> | `"my-secret-key"` |
| `input`      | The input string to hash                                          | `string` | <i class="fa-square-check">:square-check:</i> | `"data-to-sign"`  |
| `encoding`   | Output format of the hash (e.g., `"hex"`, `"base64"`, `"latin1"`) | `string` | <i class="fa-square-check">:square-check:</i> | `"base64"`        |

***

### Supported Encodings

See [Node.js crypto documentation](https://nodejs.org/api/crypto.html#cryptocreatehmacalgorithm-key-options) for full details.

Common options include:

* `hex` — Human-readable hash string
* `base64` — Compact and URL-safe
* `latin1` — Raw binary output

***

### Example Usage

```js
async function() {
    const config = {
        secret_key: this.accountvars["secret_key"],
        request_payload: this.payload,
        encoding: "base64"
    };

    return this.tools.getHmacSHA1(config.secret_key, config.request_payload, config.encoding);
}
```

In this example:

* The secret key is pulled from `accountvars`
* The full payload is used as the input
* The resulting SHA-1 HMAC is encoded in base64

***

### Use Cases

* Generate **HMAC signatures for webhooks**
* Sign requests to third-party APIs
* Validate payloads between frontend and backend
* Create tamper-resistant tokens or messages

***

### Notes

* SHA-1 HMAC is **secure for keyed hashing**, but for new applications, consider using **HMAC-SHA256** where supported.
* Make sure the secret key is securely stored (e.g., in `accountvars` or protected config).
* Encoding must always be explicitly specified.

***

### Summary

`this.getHmacSHA1` enables secure and efficient creation of **signed hashes** for request validation, secure communications, and payload protection. It is ideal for API integrations, webhook authentication, and cryptographic use cases where **data integrity and authenticity** matter.


---

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