Generate an HMAC — Free HMAC-SHA1/256/384/512 Generator

The HMAC Generator takes a message and a secret key, runs them through SHA-1, SHA-256, SHA-384, or SHA-512, and gives you the resulting HMAC in hex — proof the message wasn't altered by anyone who doesn't know the key. Type your message, enter your secret key, choose a hash algorithm, and watch the HMAC update below as you go. Everything runs locally in your browser through the Web Crypto API, so your secret key is never sent anywhere.

When you need to prove that a message arrived exactly as it was sent — and that it came from someone who holds the same secret — an HMAC generator gives you a cryptographic guarantee in seconds. Unlike a plain checksum or a bare hash, the resulting hmac signature binds your payload to a shared private key, enabling both payload signing and sender confirmation in a single compact token. Whether you are protecting a webhook endpoint, authenticating a service request, or building a token-based scheme, understanding how to generate and validate hmac online is a foundational skill in modern cryptography.

What Is an HMAC Signature Generator and How Does It Work?

HMAC stands for hash-based message authentication code — sometimes written as keyed-hash message authentication code. It is a cryptographic technique standardised in RFC 2104 that layers a secret cryptographic key on top of a standard cryptographic hash function (such as SHA-256, SHA-384, SHA-512, SHA-1, or MD5) to produce a fixed-length output that simultaneously proves content validity and sender origin. Because the private key is mixed into the computation, only a party that possesses the same shared value can produce or confirm the same tag — this is what separates HMAC from a plain hash.

The formal construction involves three components: the message (the data you want to authenticate), the key (a shared value between sender and receiver), and the hash function (the underlying method). The initialization step chooses both the hash method and a key K. During key modification, if the key is longer than the hash function's block size, it is hashed down to fit; if it is shorter, key padding brings it up to the block size with zero bytes. Two derived keys are then produced by XOR-ing the padded key against a fixed inner padding constant (ipad, 0x36 repeated) and a fixed outer padding constant (opad, 0x5C repeated). The full formula is:

$$\text{HMAC}(K,\, m) = H\bigl((K \oplus opad) \,\|\, H((K \oplus ipad) \,\|\, m)\bigr)$$

In plain language: first, the inner pass concatenates the ipad-derived key with your message content and hashes the result into an intermediate output. Then, the outer pass concatenates the opad-derived key with that intermediate value and hashes again, producing the final authentication code. This double-pass construction is deliberately resistant to length-extension attacks that can compromise simpler MAC designs, making HMAC a robust mac method for production use.

HMAC vs. Plain Hash vs. MAC — Key Differences Involving SHA-256 and Beyond

A plain hash (SHA-256, and legacy functions such as SHA-1 or MD5) is a one-way function anyone can compute from the message alone. It confirms that the content has not been altered, but it offers zero confirmation of origin: an attacker who intercepts and replaces a message can simply recompute a fresh hash to match. A generic MAC method requires a key but may lack the standardised security proof that HMAC carries. HMAC bridges both gaps: it provides message integrity through keyed processing and origin confirmation through the shared value, making it the standard choice for service request protection, webhooks, and token signing (HS256, HS384, HS512).

FeaturePlain HashMACHMAC
Requires a keyNoYesYes (keyed-hash)
Proves message integrityYesYesYes
Proves sender identityNoDependsYes
Resistant to length-extensionNoVariesYes
Use for password storageNoNoNo
Common use casesChecksums, file integritySpecific MAC protocolsAPI auth, webhooks, JWT

Common real-world applications include service request validation (attaching an hmac-sha256 output of the path plus a timestamp to each outbound call), webhook payload signing (Stripe, GitHub, and Slack all use HMAC to let your server confirm that an incoming webhook genuinely came from the platform), signed cookies protecting session data from client-side tampering, and token schemes where the HS256 method (HMAC-SHA256) covers the header-plus-payload pair. The shared private value is the linchpin: as long as only the sender and receiver possess it, a valid tag is proof of both origin and content validity.

Using This HMAC Generator Tool to Generate and Verify Signatures

This browser-based hmac-sha256 online tool uses the Web Crypto API (the webcrypto library built into every modern browser) to perform all computation locally. It runs in browser — your message, your private key, and the resulting tag are computed entirely client-side; no data transmitted to any server, never sent to a third-party, and not stored outside localStorage. Because all processing happens locally in browser, you can safely test real keys and payloads during development without risking exposure — the data never leaves device. This tool operates as a fully key-based, client-side solution and the computed value is never sent to any backend, qualifying it among the most privacy-respecting developer tools available for this purpose.

Supported Algorithms, Output Format, and Secret Key Options

The hmac calculator supports the following methods. Choose based on your integration's requirements; prefer sha-256 for new work and fall back to older options only when a specific integration demands it.

AlgorithmJWT NameOutput Length (hex)PurposeUse for Passwords?
HMAC-MD5 (hmac-md5)32 hex charsLegacy message authentication❌ No
HMAC-SHA-1 (sha-1-based hmac)40 hex charsLegacy content checks❌ No
HMAC-SHA-256 (HS256)HS25664 hex charsService signing, webhooks, JWT❌ No
HMAC-SHA-384 (hmac-sha384)HS38496 hex charsHigher-assurance confirmation❌ No
HMAC-SHA-512 (HS512)HS512128 hex charsMaximum output size, large payloads❌ No

Output format — choose between hex (base16 encoding, sometimes called hex encoding or a b16 result) and base64 (a b64 result using standard base64 output). Both encoded results represent the same underlying bytes — different representations of the same value — so pick whichever your platform expects. GitHub webhooks use hex output; many other webhook providers prefer base64 output or even base64url (URL-safe base64, used in JWT signatures). Base16 results are not case sensitive; base64-encoded values are case sensitive, so match the casing exactly during validation.

Message encoding notes: the tool converts your input to UTF-8 bytes before computing the HMAC, consistent with standard UTF-8 encoding. String formatting matters: whitespace significant — every space, tab, newline, and line-break is part of the message. A trailing newlines difference between your local copy and the remote payload will produce a completely different output. The tool converts line-breaks to \n and strips carriage-return (CR) characters automatically. Unicode input is fully supported via UTF-8. To test empty-input behaviour, use a blank message — the HMAC over an empty string with a given key is a valid and deterministic tag.

To verify hmac signatures, paste the HMAC you received (from a webhook provider, a service callback, or a remote system) into the verification field and the tool will recompute the tag over the same message and private key, then perform secure comparing of the two values. A match confirms the message was not tampered with and came from the claimed sender.

Verification warnings: the most common reason a check fails is a mismatch in either the private key or the method. If you used hmac-sha256 to sign but paste the received value into an HS512 check, the tool will report a mismatch even though your key is correct. Always confirm both the method and the output encoding (hex vs. base64) match the sender's settings before concluding a tag is invalid.

Worked Examples: Service Signing, Webhook Validation, and JWT with the HMAC Signature Generator/Verifier

The three worked examples below demonstrate hmac calculation in concrete, step-by-step form so you can trace exactly how the hash and hmac calculator derives each result. All examples use HMAC-SHA256 and produce hex output unless stated otherwise. These cover the most common developer scenarios: service request signing, webhook payload validation, and building the signature component of a JWT. This free online tool runs the same computation automatically as you type.

Example 1 — Service Request Signing with HMAC-SHA256

Scenario: your application must add a content-validation tag to each outbound REST call so the receiving server can confirm the request was not modified in transit. This is a classic request-signing workflow common across developer tools and service integrations.

  1. Identify the message: concatenate the HTTP method, path, and JSON body into a canonical string — for example, POST /orders {"amount":99,"currency":"USD"}. This is your plain-text format input.
  2. Set the private key: use a 32-byte cryptographically random value, e.g. s3cr3tK3y!2024xYz — keep it confidential in your application configuration and never commit it to source control.
  3. Select the method: choose HMAC-SHA256 (HS256) in the hmac generator tool.
  4. Compute the tag: the tool produces a hex output such as 9946dad4e00e913fc8be8e5d3f7e110a4a9e832f83fb09c345285d78638d8a0e — your hmac output.
  5. Attach the tag: send it as an X-Signature-HMAC-SHA256 request header. The server-side logic recomputes it identically and compares; if they match, the request is confirmed as authentic.

The formula executed internally during this hmac calculation is:

$$\text{HMAC-SHA256}(\text{key},\, \text{message}) \rightarrow \text{64-char hex output}$$

Example 2 — Webhook Payload Validation (Incoming Webhook from an External System)

Scenario: you operate a server endpoint that receives incoming webhook POST requests from a webhook provider — for instance, a Stripe webhook, GitHub webhook, or Slack webhook. Each request carries a tag header; your job is to confirm that the payload has not been altered by an external system or a man-in-the-middle before processing payloads.

  1. Read the raw body: capture the exact byte sequence of the HTTP request body — {"event":"payment.completed","id":"evt_001"}. Do not parse JSON first; whitespace differences will break the content check.
  2. Retrieve the shared key: your private value agreed with the provider during registration. Treat it as confidential information.
  3. Compute the tag: paste the body and the shared key into the tool and select SHA-256. The tool performs automatic computation and shows the hex output.
  4. Compare tags: use recomputation logic on the server and compare your computed value against the value in the X-Hub-Signature-256 (GitHub) or Stripe-Signature header using a constant-time comparison to prevent timing attacks. A mismatch means either the body was modified or the wrong key was used — the payload was potentially tampered with.

This webhook validation pattern — recompute on arrival, then compare — stops replay attacks and forgeries because any change to the payload changes the output entirely, and only a holder of the private value known to both sides can produce a matching tag. It is the confirmation scheme used across nearly all major service platforms.

Example 3 — JWT HS256 Signature Component

Scenario: you are building or debugging a JWT token (JSON Web Token) that uses the HS256 method — HMAC-SHA256. The tag covers the encoded header and payload so that any tampering with the token body invalidates the token. JWT also uses HS384 and HS512 (HMAC with SHA-384 and SHA-512, respectively) for larger outputs.

  1. Encode header and payload: base64url-encode the JSON header {"alg":"HS256","typ":"JWT"} and the payload {"sub":"user_42","iat":1700000000} separately, then join with a dot: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzQyIiwiaWF0IjoxNzAwMDAwMDAwfQ.
  2. Set the private key: use your application's token-signing key — store it in secrets management and rotate it on a schedule.
  3. Generate HMAC online: paste the dot-joined string as the message and your key into the hmac generator/verifier. Select HMAC-SHA256 and set output to base64url encoding.
  4. Append the tag: the base64url-encoded output forms the third segment of your JWT — header.payload.<hmac-output>. This is the signed message that a receiving server can confirm by recomputing over the first two segments with the shared key.

In JWT terminology, HS256 maps directly to HMAC-SHA256; HS384 maps to HMAC-SHA384; HS512 maps to HMAC-SHA512. The message output calculation is identical to the standalone HMAC case — only the representation of the input and the output format differ. Use a dedicated JWT & JWE Debugger or JWK generator alongside this tool when building full token flows involving SAML, TOTP, passkey, or WebAuthn.

Best Practices and When Not to Use the HMAC Calculator

Applying HMAC correctly involves more than just choosing the right method. The following guidance covers key management, method selection, and the important boundary cases where HMAC is not the right cryptographic tool — including when to reach for aes encryption, asymmetric approaches, or a dedicated credential hashing function.

  • Use a cryptographically random private key: generate your signing key with a CSPRNG (cryptographically secure pseudo-random number generator), not a human-readable passphrase. For SHA-256, a 256-bit (32-byte) key is the recommended minimum; for SHA-512, 512 bits. Short or guessable keys undermine protection entirely.
  • Prefer SHA-256 or stronger: avoid legacy SHA-1-based HMAC and legacy MD5-based HMAC in any new system. Both older functions are supported here for testing legacy integrations and tag migration, not for production new systems.
  • Rotate keys periodically: implement regular key rotation as part of your secrets management strategy. After rotation, provide a short overlap window where the old key still validates incoming requests to avoid broken integrations — plan for tag migration before decommissioning old keys.
  • Use constant-time comparison to prevent timing attacks: when recomputing server-side, always compare the expected and received tags with a constant-time equality function. Naive string comparison leaks timing information that allows an attacker to brute-force one byte at a time. This is the most commonly missed best practice in HMAC validation implementations.
  • Keep the private key confidential: never embed your signing key in client-side JavaScript, commit it to a public repository, or log it. Store it in environment variables or a dedicated secrets management vault. Treat exposure as an immediate key rotation trigger.
  • Validate method on receipt: always enforce which method you accept — do not trust a method field from a token header without validating it server-side. This prevents downgrade attacks that switch from SHA-256 to a weaker function silently.

When HMAC Is the Wrong Tool — Password Hashing, Asymmetric Verification, and More

Credential storage: HMAC is not a password hashing function. It is fast by design — which makes it unsuitable for credential storage. An attacker with a leaked database can try billions of guesses per second against HMAC-SHA256 outputs using GPU hardware. For protecting stored credentials, use a memory-hard, gpu-resistant key derivation function instead: argon2 is the modern standard (winner of the Password Hashing Competition), or pbkdf2 for environments requiring a widely-supported key derivation method. Neither argon2 nor PBKDF2 is a mac generator — they are purpose-built for stretching values against offline brute-force.

Asymmetric verification (public confirmation without a shared key): HMAC requires that the verifier also holds the private key. If you need to let the public confirm a tag without sharing a private value — for example, a software distribution tag or a legally binding digital signature — use asymmetric approaches such as RSA (RSASSA-PKCS1-v1_5 or RSA-PSS) or ECDSA. These use a private key to sign and a public key to confirm; only the sender side needs the private key. They are a better fit for authorization flows that involve a broad verifier audience. HMAC is best when only the sender and receiver are involved and both can safely hold the same key.

When you need encryption, not authentication: HMAC proves that data is authentic and not tampered; it does not provide privacy or confidentiality. If your requirement includes hiding the message content from third parties — combine HMAC with symmetric aes encryption (encrypt-then-MAC) or use an authenticated mode such as AES-GCM, which handles content protection and confidentiality together. HMAC alone over a plain-text format is not a substitute for a cipher.

High-performance MAC with modern stream ciphers: if throughput is critical and you are already using a ChaCha20-based cipher, consider poly1305 (the Poly1305 MAC generator) instead of HMAC. Poly1305 is a one-time MAC designed to work with chacha20, offering strong message confirmation with excellent performance on constrained devices. It is a different mac format but fills a similar role.

For broader developer workflows involving data authenticity and identity, this hmac generator pairs naturally with a hash generator, a hash calculator for standalone output confirmation, a Base64 Encoder/Decoder for base64 conversions, a JWT generator for full token workflows, and a UUID generator for correlation IDs. Together, they cover the most common needs in service protection, web, and browser workflows — with all computation staying on your device, open source logic available for audit, and zero risk from server-side handling. Your privacy is protected because the tool is designed so that no data transmitted beyond your browser tab — it is computed client-side and the message is never sent to any external backend, making it safe even for sensitive test cases and staging environment callbacks. This approach to data authenticity and reliable content checks is a cornerstone of modern web crypto practice, and using a browser-based hmac generator that runs entirely client-side is the safest way to generate hmac online without compromising your private keys.

Frequently Asked Questions

What's the difference between HMAC and a plain hash?
A plain hash (like SHA-256 alone) only proves a message hasn't changed if the hash itself is protected from tampering -- anyone can recompute a plain hash. HMAC combines the message with a secret key using a specific construction (HMAC(K,m) = H((K⊕opad) || H((K⊕ipad) || m))), so only someone who knows the secret key can produce or verify a matching HMAC -- it proves both integrity and authenticity.
What is HMAC commonly used for?
Verifying webhook payloads (many APIs sign requests with an HMAC so you can confirm they really came from that service), API request signing, JWT signature verification (the HS256/HS384/HS512 algorithms are exactly HMAC-SHA256/384/512), and session token integrity checks.
Which hash algorithm should I use?
HMAC-SHA256 is the most common modern default and is what this tool selects by default. Use whichever algorithm the system you're integrating with specifies -- HMAC's security only requires the underlying hash to be reasonably strong, so SHA-1 is still acceptable for HMAC (unlike for plain hashing) even though it's deprecated elsewhere, but SHA-256 or better is preferred for new systems.
Can I verify an HMAC I received, not just generate one?
Yes -- enter the same message and the same secret key the sender used, and compare this tool's output to the HMAC value you received. If they match exactly, the message is verified as authentic and unmodified.
Is my message or secret key sent anywhere?
No. The entire HMAC computation runs locally using the Web Crypto API -- neither the message nor the secret is ever transmitted to a server or stored.