Format Code Now
/

HMAC Generator

HG-05

Put the secret key on the first line and the message below it to get the HMAC as hex or Base64. Choose HMAC-SHA-256, SHA-512, SHA-384 or SHA-1.

Runs in your browser. Nothing is uploaded.

Secret key on the first line, message on the lines below

HMAC

How to use it

  1. Type the secret key on the first line of the box, then press Enter and type or paste the message. Sample shows the layout.
  2. Pick the algorithm. HMAC-SHA-256 is the usual choice.
  3. If your key is written as hex bytes, set Key is to Hex bytes.
  4. Choose hex or Base64 output, then copy the result or download it.

How the single box works

The first line is the secret key. Everything after the first line break is the message, kept exactly as typed, including spaces and a final line break. That matters for webhooks and signed requests, where the signature covers the raw body byte for byte. A key typed as text is encoded as UTF-8. Choose Hex bytes if the key is given as hex, for example in a test vector. There must be a line break after the key, even when the message is empty.

What an HMAC proves, and what it does not

An HMAC is a hash that depends on a secret key. Whoever holds the key can compute it and check it, so a matching value shows the message came from a key holder and was not changed. It does not hide the message, and it does not work without a shared secret. Keys of any length work, including empty keys and keys longer than the hash block size, which are hashed first as RFC 2104 describes. Results are tested against the RFC 4231 vectors.

Choosing an algorithm

HMAC-SHA-256 is the common default for webhooks, API request signing and tokens. HMAC-SHA-512 and HMAC-SHA-384 give longer values. HMAC-SHA-1 appears in older protocols; known collision attacks on SHA-1 do not directly break HMAC-SHA-1, but prefer SHA-256 for anything new. The algorithm must match the one the other side uses, because each gives a different value for the same key and message.

Error messages and what to do

MessageWhat it meansFix
Put the secret key on the first line and the message on the lines below it.The box has only one line, so there is no line break between the key and the message.Press Enter after the key and type the message on the next line. For an empty message, add the line break and leave it blank.
The key is not valid hex: use only 0-9 and a-f (spaces and colons are ignored).Key is set to Hex bytes, but the first line holds other characters.Remove the stray characters, or set Key is back to Text.
The key is not valid hex: it has an odd number of digits.Hex bytes need two digits each, and the first line has one digit left over.Add the missing digit, or a leading 0, so every byte has two digits.

Questions people ask

How do I generate an HMAC SHA-256 online?

Type the secret key on the first line of the box, press Enter, and type or paste the message below. Keep HMAC-SHA-256 selected and the result appears as hex, or switch it to Base64. The calculation runs in your browser, and no key or message is sent anywhere.

What is the difference between a hash and an HMAC?

A plain hash such as SHA-256 has no secret, so anyone can recompute it from the message. An HMAC mixes in a secret key, so only someone with the key can create or verify the value. Use an HMAC when a receiver needs to know a message is authentic.

Why does my HMAC not match the one from my code?

Check the key and the message bytes. Common causes are a key that is hex in your code but text here, an extra trailing newline, different line endings, or a different algorithm. Set Key is to Hex bytes for hex keys, and compare the message exactly, character for character.

How do I check a webhook signature?

Many webhook providers sign the raw request body with HMAC-SHA-256. Put the signing secret on the first line and the exact raw body below it, then compare the output with the signature in the header. Some providers add a timestamp or a prefix to the signed text, so read their documentation.

Is HMAC-SHA-1 still secure?

Known collision attacks on SHA-1 do not directly break HMAC-SHA-1, and it is still used in older protocols. For new designs prefer HMAC-SHA-256, since it avoids any doubt and costs almost nothing extra. Use HMAC-SHA-1 here only to match a system that requires it.

Can I use a hex key or an empty key?

Yes to both. Set Key is to Hex bytes and put the hex on the first line, with spaces and colons ignored. An empty key works too: leave the first line blank and start the message on the second line. A key longer than the hash block size is hashed first.

About this tool

The first line of the box is the secret key and everything after the first line break is the message, kept exactly as typed, including a trailing line break. The key can be plain text or hex bytes. Empty keys and keys longer than the hash block size work, as in RFC 2104. The SHA-2 variants are checked against the RFC 4231 test vectors and SHA-1 against the crypto module in Node. An HMAC proves that someone with the key made the message; it does not hide the message. The key and message are not sent anywhere, but avoid pasting a live production secret into any web page you do not control.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.