Search tools...

Search tools...

HMAC Generator

Generate HMAC (Hash-based Message Authentication Code) with SHA-1, SHA-256, SHA-384, or SHA-512. Used for API authentication and message integrity.

Enter message and key to generate HMAC

ℹ️ About HMAC: HMAC (Hash-based Message Authentication Code) combines a cryptographic hash with a secret key to verify both data integrity and authenticity.

How HMAC Generator Works

HMAC (Hash-based Message Authentication Code) is a high-security mechanism used to verify both the Data Integrity and the Authenticity of a message. Defined in RFC 2104, it combines a cryptographic hash function (like SHA-256) with a secret cryptographic key. Unlike a simple hash, an HMAC can only be reproduced by someone who possesses the original secret key, making it the "Gold Standard" for Webhooks, API signatures, and network security.

The HMAC algorithm follows a rigorous "Double-Hashing" process:

  1. Key Pre-processing: If the secret key is longer than the hashing block size (e.g., 64 bytes for SHA-256), it is hashed first. If it's shorter, it is padded with zeros.
  2. Inner Padding (IPAD): The processed key is XORed with a specific repeated byte (0x36).
  3. Inner Hash: The message data is appended to this inner-padded key, and the resulting string is hashed.
  4. Outer Padding (OPAD): The processed key is XORed with a different repeated byte (0x5c).
  5. Outer Hash: The result of the Inner Hash is appended to the outer-padded key, and the entire sequence is hashed one final time.
  6. Final Digest: This "Nested" hashing ensures that the resulting HMAC is resistant to "Length-Extension Attacks" that can plague simple hash-plus-key combinations.

The History of HMAC and Hugo Krawczyk

The HMAC specification was developed in 1996 by Hugo Krawczyk, Mihir Bellare, and Ran Canetti. They realized that simply concatenating a key and a message (e.g., hash(key + message)) was vulnerable to dangerous mathematical attacks.

Their solution, the "Nested Hash," was so robust that it was quickly adopted as an Internet Standard. Today, HMAC is the engine behind JSON Web Tokens (JWT), the AWS Signature V4 process, and the IPsec protocol.

Technical Comparison: HMAC vs. Digital Signatures vs. Checksums

Understanding when to use a shared secret vs. a public/private key pair is fundamental for API design.

Feature HMAC (Symmetric) Digital Signatures (RSA) Checksums (MD5)
Trust Model Shared Secret Key Public / Private Key No Key (Open)
Authenticity? Yes Yes (Non-repudiation) No
Integrity? Yes Yes Yes
Speed Extremely Fast Very Slow Extremely Fast
Common Use API Auth / Webhooks Legal Docs / HTTPS File Verification

By using a dedicated HMAC Generator, you can accurately simulate API Request Signing and debug incoming webhooks from platforms like Stripe, GitHub, or Shopify.

Security Considerations: Secret Key Management

The security of an HMAC depends entirely on the secrecy of the key:

  • Key Entropy: Always use a long, random secret key. A weak key can be "Brute-Forced" by an attacker who has captured one of your HMAC signatures.
  • Timing Attacks: When verifying an HMAC on your server, always use a Constant-Time Comparison function (like crypto.timingSafeEqual in Node.js) to prevent attackers from guessing the hash bit-by-bit.
  • Algorithm Strength: While HMAC can work with any hash, HMAC-SHA256 is currently the recommended standard for web security.
  • Client-Side Privacy: To maintain absolute Data Privacy, the entire HMAC generation happens locally in your browser. Your secret keys and private message data are never sent to our servers.

Frequently Asked Questions

No. Like all hashes, HMAC is a one-way function. You cannot extract the message or the secret key from the resulting HMAC string.