> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# computeHmac

```ts theme={null}
function computeHmac(
   algorithm, 
   _key, 
   _data): string
```

Return the HMAC for `data` using the `key` key with the underlying `algo` used for compression.

## Parameters

| Parameter   | Type                                               | Description                           |
| :---------- | :------------------------------------------------- | :------------------------------------ |
| `algorithm` | `"sha256"` \| `"sha512"`                           | The algorithm to use for compression. |
| `_key`      | [`BytesLike`](/sdk/content/type-aliases/BytesLike) | The key to use for the HMAC.          |
| `_data`     | [`BytesLike`](/sdk/content/type-aliases/BytesLike) | The data to authenticate.             |

## Returns

`string`

The HMAC of the data.

## Example

```js theme={null}
key = id('some-secret');

// Compute the HMAC
computeHmac('sha256', key, '0x1337');

// To compute the HMAC of UTF-8 data, the data must be
// converted to UTF-8 bytes
computeHmac('sha256', key, toUtf8Bytes('Hello World'));
```

## Source

[crypto/hmac.ts:41](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/crypto/hmac.ts#L41)
