Go back to dialerseat.comsales@dialerseat.com
Free tool

HMAC generator

Type a message and a secret key, pick the hash, and get the HMAC as hex and base64, the two encodings senders put in signature headers. It runs in your browser with the Web Crypto API, so nothing you type is sent anywhere: open your network tab and check. To test it, the key "key" and the message "The quick brown fox jumps over the lazy dog" give f7bc83f4…3cd8 with SHA-256.

How an HMAC is made

HMAC, defined in RFC 2104, hashes the message twice with the key folded in: once with the key mixed with one fixed pad, and again over that result with the key mixed with a second pad. The output is as long as the hash: 32 bytes for SHA-256, written as 64 hex characters or 44 base64 characters. The receiver repeats the calculation with its own copy of the key and compares, in constant time, never with ==.

Hex or base64

The bytes are the same; only the spelling differs. GitHub and Stripe send hex. Shopify sends base64. If your value never matches, check the encoding before you suspect the key. A full list of the usual causes is in webhook signature verification failed.

Code

Node.js
import crypto from 'node:crypto'

const hex = crypto.createHmac('sha256', secret).update(message).digest('hex')
const b64 = crypto.createHmac('sha256', secret).update(message).digest('base64')
Python
import hashlib, hmac, base64

digest = hmac.new(secret.encode(), message.encode(), hashlib.sha256)
hex_value = digest.hexdigest()
b64_value = base64.b64encode(digest.digest()).decode()
PHP
$hex = hash_hmac('sha256', $message, $secret);
$b64 = base64_encode(hash_hmac('sha256', $message, $secret, true));
Go
import (
    "crypto/hmac"
    "crypto/sha256"
    "encoding/hex"
)

mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(message))
hexValue := hex.EncodeToString(mac.Sum(nil))

Questions

What is the difference between an HMAC and a hash?

Anyone can compute a plain hash such as SHA-256 of a message. An HMAC mixes a secret key into the hash, so only someone holding the key can produce it. That proves who sent the message and that it was not changed on the way.

Is HMAC symmetric or asymmetric?

Symmetric. The same secret signs and verifies, so both sides must hold it. A digital signature such as RSA or ECDSA is asymmetric: a private key signs and a public key verifies.

How long should an HMAC key be?

RFC 2104 discourages keys shorter than the hash output, which is 32 bytes for SHA-256. Keys longer than the hash's block size are hashed first, so a random key of 32 to 64 bytes is the usual choice for HMAC-SHA256.

HMAC or JWT?

They are not alternatives. A JWT is a token format; a JWT signed with HS256 carries an HMAC-SHA256 of its header and payload. Webhooks usually send a bare HMAC of the body in a header instead.

Why is HMAC-MD5 not offered?

The browser's Web Crypto API, which this page uses so nothing leaves your machine, does not implement MD5. Use SHA-256 for anything new.


To check a whole webhook delivery, with its timestamp and header, use the webhook signature checker. DialerSeat for Developers signs its webhooks with HMAC-SHA256 over the timestamp, a dot and the raw body; read the webhooks docs or get sandbox keys.