Skip to content
ToolkitHub

HMAC Generator

Generate HMAC signatures

Guide

How HMAC signatures prove a message is authentic

By Logappradeep · ServiceNow developer

A plain hash tells you whether data changed, but anyone can compute it, so it cannot tell you who produced the data. HMAC (Hash-based Message Authentication Code) fixes that by mixing a secret key into the hash. Only parties who know the key can produce a valid signature, so a matching HMAC proves both that the message is intact and that it came from someone holding the key.

How HMAC is computed

HMAC, defined in RFC 2104, runs the underlying hash twice with the key folded in through two fixed padding constants:

HMAC(K, m) = H( (K' xor opad) || H( (K' xor ipad) || m ) )

Here K' is the key padded to the hash's block size, and || means concatenation. This nested construction is why you should never build your own signature as SHA256(key + message): that naive form is vulnerable to length-extension attacks on SHA-256, while HMAC is not.

A standard test vector: with the key key and the message The quick brown fox jumps over the lazy dog, HMAC-SHA256 produces f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8. Enter those values here to confirm the tool matches your own implementation.

Where you meet HMAC

  • Webhooks. Payment processors, Git hosts and chat platforms sign each webhook body with HMAC-SHA256 and send the signature in a header so your server can verify it.
  • API request signing. Cloud providers sign requests with HMAC so the secret itself never travels over the network.
  • JWTs. The HS256 algorithm is HMAC-SHA256 over the token's header and payload.
  • Signed cookies and links that must not be altered by the client.

Pitfalls when verifying signatures

Sign the exact bytes. Webhook signatures are computed over the raw request body. If your framework parses the JSON and you re-serialize it, spacing or key order can change and the signature will never match. Read the raw body before parsing.

Match the encoding. This tool outputs lowercase hexadecimal. Some services send Base64 or prefix the value, as in sha256=.... Compare like with like.

Compare in constant time. A normal string comparison returns as soon as one character differs, which can leak timing information. Use a constant-time function such as Node's crypto.timingSafeEqual.

Key format. The key here is treated as UTF-8 text. If a provider gives you a hex or Base64 key that is meant to be decoded to raw bytes first, the result will differ.

HMAC-SHA1 and HMAC-MD5 are not broken in the way plain SHA-1 and MD5 are, but HMAC-SHA256 or HMAC-SHA512 is the right choice for new systems. Signatures are computed in your browser. The message and key fields are remembered in local storage, so avoid entering production secrets on a shared computer.

Frequently asked questions

What is the difference between a hash and an HMAC?

Anyone can compute a hash of public data. An HMAC also requires a secret key, so it proves the message came from someone who holds that key.

Why doesn't my webhook signature match?

The most common causes are signing a re-serialized body instead of the raw bytes, comparing hex to Base64, or including a prefix like sha256= in the comparison.

Is HMAC-SHA1 still secure?

HMAC-SHA1 has no practical known attack, but it is considered legacy. Use HMAC-SHA256 or HMAC-SHA512 for new designs.

Is my secret key uploaded?

No. The HMAC is computed in your browser, though the key is kept in local storage for convenience, so clear it on shared machines.