> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Hash.hmac256

:::info
`Hash.hmac256` is a re-export of ox's [`Hash.hmac256`](https://oxlib.sh/api/Hash/hmac256). Refer to the ox documentation for the full reference.
:::

Calculates the [HMAC-SHA256](https://en.wikipedia.org/wiki/HMAC) of a [`Bytes.Bytes`](/docs/utilities/bytes/types#bytes) or [`Hex.Hex`](/docs/utilities/hex/types#hex) value.

Backed by `hmac` from [`@noble/hashes`](https://github.com/paulmillr/noble-hashes), an audited & minimal JS hashing library, unless another implementation is installed with [`Engine.set`](https://oxlib.sh/api/Engine/set).

## Imports

```ts
import { Hash } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { Hash, Hex } from 'viem/utils'

Hash.hmac256(Hex.fromString('key'), '0xdeadbeef')
// @log: '0x...'
```

### Configure Return Type

```ts twoslash
// @noErrors
import { Hash, Hex } from 'viem/utils'

Hash.hmac256(Hex.fromString('key'), '0xdeadbeef', {
  as: 'Bytes'
})
// @log: Uint8Array [...]
```

## Definition

```ts
function hmac256<value, as>(
  key: Hex.Hex | Bytes.Bytes,
  value: value | Hex.Hex | Bytes.Bytes,
  options?: hmac256.Options<as>,
): hmac256.ReturnType<as>
```

## Parameters

### key

* **Type:** `Hex.Hex | Bytes.Bytes`

[`Bytes.Bytes`](/docs/utilities/bytes/types#bytes) or [`Hex.Hex`](/docs/utilities/hex/types#hex) key.

### value

* **Type:** `value | Hex.Hex | Bytes.Bytes`

[`Bytes.Bytes`](/docs/utilities/bytes/types#bytes) or [`Hex.Hex`](/docs/utilities/hex/types#hex) value.

### options

* **Type:** `hmac256.Options<as>`
* **Optional**

Options.

#### options.as

* **Type:** `"Bytes" | "Hex" | as`
* **Optional**

The return type.

## Return Type

HMAC-SHA256 hash.

`hmac256.ReturnType<as>`
