HMAC Generator

Generate an HMAC (Hash-based Message Authentication Code) from text and a secret key. This online HMAC calculator supports HMAC-SHA-1, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512; accepts text, hexadecimal, or Base64 keys; and returns a lowercase hexadecimal tag. Calculation runs locally in your browser.

Secret key
Input
0 chars · 0 bytes
Try:
Hash
✓ Client-side processing only ✓ Input is not sent to server
Examples
Empty message
Key: secret Algorithm: hmac-sha-256 Key format: text
Input (empty)
Output f9e66e179b6747ae54108f82f8ade8b3c25d76fd30afde6c395822c530196169

An empty message is valid input. HMAC-SHA256 still produces a 64-character hex tag from the key "secret".

Text key
Key: secret Algorithm: hmac-sha-256 Key format: text
Input hello world
Output 734cc62f32841568f45715aeb9f4d7891324e6d948e4c6c60c0621cdac48623a

HMAC-SHA256 of "hello world" using the UTF-8 text key "secret".

Another message and key
Key: key Algorithm: hmac-sha-256 Key format: text
Input hello
Output 9307b3b915efb5171ff14d8cb55fbcc798c6c0ef1456d66ded1a6aa723a58b7b

Changing either the message or the secret key produces a different HMAC-SHA256 tag.

RFC 4231 HMAC-SHA256 test vector
Key: 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b Algorithm: hmac-sha-256 Key format: hex
Input Hi There
Output b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7

RFC 4231 test case 1 uses a 20-byte key represented as hex and provides a standard value for checking HMAC-SHA256 implementations.

What is HMAC?

HMAC (Hash-based Message Authentication Code) is a standard construction that combines a cryptographic hash function with a secret key. Defined in RFC 2104, it converts a message of any length into a fixed-length authentication tag. HMAC-SHA256 is the most common modern variant, while HMAC-SHA384 and HMAC-SHA512 provide longer tags and HMAC-SHA1 remains in some legacy protocols.

A recipient who has the same secret key can calculate the HMAC again and compare it with the received tag. A match provides evidence that the message has not changed and was produced by a party that knows the shared key. Unlike a plain SHA-256 hash, an attacker cannot create a valid replacement tag without the key. HMAC is a symmetric message authentication code, not encryption and not a public-key digital signature.

How HMAC works

In simplified notation, HMAC computes H((K' ⊕ opad) || H((K' ⊕ ipad) || message)). The key is first normalized to the hash function's block size, then combined with two different padding constants for the inner and outer hash operations. This construction avoids the length-extension problem that affects naive schemes such as hash(key || message).

The selected hash determines the full tag length: HMAC-SHA1 produces 20 bytes (40 hex characters), HMAC-SHA256 produces 32 bytes (64 hex characters), HMAC-SHA384 produces 48 bytes (96 hex characters), and HMAC-SHA512 produces 64 bytes (128 hex characters). This generator displays the complete tag as lowercase hexadecimal and does not truncate it.

How to use the HMAC generator
  1. Enter or paste the exact message in the input field.
  2. Select HMAC-SHA256, HMAC-SHA1, HMAC-SHA384, or HMAC-SHA512.
  3. Choose how the key is represented: text, hex, or Base64.
  4. Enter the secret key. The HMAC calculator updates the lowercase hex result, which you can copy.

The message is always encoded as UTF-8 text. In text mode, the key is also encoded as UTF-8; in hex or Base64 mode, the key is decoded into its original bytes first. Spaces, line endings, letter case, Unicode characters, algorithm choice, and key format all affect the result.

HMAC for APIs, webhooks, and JWTs

HMAC commonly authenticates API requests, webhook payloads, session data, and protocol messages. A typical verification flow receives a message and tag, recalculates the HMAC over the exact original bytes with the shared secret, and compares the tags using a constant-time comparison. Production schemes may also include a timestamp or nonce to prevent replay attacks.

Follow the specification of the system you are integrating with. API signature schemes often require a canonical request string; webhook providers may sign the raw HTTP body; and JWT HS256 signs the Base64URL-encoded header and payload and represents the signature in Base64URL rather than hex. This page calculates an HMAC for the text you enter, but it does not build provider-specific canonical strings, parse requests, convert the result to Base64URL, or automatically verify a supplied tag.

FAQ

Use HMAC when two parties share a secret and need to detect deliberate message changes or authenticate a sender that knows that secret. A plain hash such as SHA-256 has no key, so anyone who changes the message can calculate a new hash. For public verification without a shared secret, use an appropriate public-key digital signature instead.

For HMAC-SHA256, a randomly generated 32-byte key is a strong default. Generate keys with a cryptographically secure random number generator and store them in a secrets manager or another protected location; hex or Base64 can represent the random bytes as text. Avoid passwords, memorable phrases, reused secrets, and keys embedded in client-side code.

Production HMAC keys are byte sequences, but configuration systems often store those bytes as hex or Base64 text. Select the format that describes your stored key: text encodes the characters as UTF-8, while hex and Base64 decode the entered string into bytes. The visible strings "616263", "YWJj", and "abc" represent the same bytes only when their matching hex, Base64, and text modes are selected.

The HMAC calculation runs locally through the browser's Web Crypto API; the message and key are not submitted to the server for calculation. If preference storage is enabled, the page can retain form settings, including the key field, in that browser's local storage. Clear the field and site data on a shared device, and do not expose production secrets to a browser or website you do not trust.

Use the algorithm required by the protocol or the party verifying the tag. HMAC-SHA256 is a widely supported default for new integrations. HMAC-SHA384 and HMAC-SHA512 are suitable when a specification requires them. Keep HMAC-SHA1 only for compatibility with an existing system; do not substitute algorithms, because each one produces a different tag.

No. HMAC is a one-way authentication function, so there is no HMAC decoder that recovers the message or secret key from the tag. Verification requires the original message and the same secret key: calculate the tag again and compare it with the expected value.

Select the same algorithm and key format, enter the exact original message and key, and compare the generated tag with the expected tag. In application code, decode both tags to bytes and use a constant-time comparison function to reduce timing side channels. This online generator calculates the candidate HMAC but does not provide an automatic verification field.

A mismatch means at least one input byte or parameter differs. Check the hash algorithm, key format, key bytes, message encoding, capitalization, leading or trailing spaces, JSON serialization, Unicode normalization, and line endings. For APIs and webhooks, confirm whether the provider signs the raw request body or a precisely defined canonical string and whether its published tag is hex, Base64, or Base64URL.

HS256 uses HMAC-SHA256, but a valid JWT requires more than hashing arbitrary JSON. It signs the ASCII Base64URL-encoded header and payload joined by a period, then encodes the signature bytes as Base64URL without padding. This tool returns a hexadecimal HMAC, so it is useful for checking the underlying calculation but does not create a complete JWT.
Related tools