Xerobit

HMAC SHA256 Generator

Enter a secret key and a message to compute an HMAC SHA256 message authentication code. You can also pick SHA-1, SHA-384 or SHA-512, and enter the key or message as text or hex. The result shows in hex and base64, computed in your browser.

Result

5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
  • Hex
    5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
  • Base64
    W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM=
  • Algorithm
    HMAC-SHA256
  • Length
    32 bytes

How to use the hmac sha256 generator

  1. Enter your secret key and choose whether it is plain text or hex bytes (for example 4a656665 is the text "Jefe").
  2. Type or paste the message and pick text or hex for it as well.
  3. Select the algorithm: HMAC-SHA256, SHA-1, SHA-384 or SHA-512.
  4. Read the hex and base64 results below. The output updates as you type.

How HMAC works

HMAC (Hash-based Message Authentication Code) combines a secret key with a message using a cryptographic hash function. The algorithm defined in RFC 2104 pads the key to the hash block size, then computes two nested hashes:

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

Here, K' is the key padded or hashed to exactly one block length. ipad is the byte 0x36 repeated for the full block, and opad is 0x5c repeated. For HMAC SHA256, the block size is 64 bytes and the inner hash produces 32 bytes. If the provided key exceeds 64 bytes, it is first hashed with SHA-256 to produce a 32-byte key, which is then zero-padded to 64 bytes.

RFC 4231 test vectors

RFC 4231 publishes HMAC test vectors for the SHA-2 family, and RFC 2202 does the same for SHA-1. You can reproduce any row below by choosing the matching key format, so they double as a sanity check for your own code. Keys are shown in hexadecimal.

CaseKey (hex)MessageAlgoHex output
10b x 20Hi ThereSHA-256b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7
24a656665what do ya want for nothing?SHA-2565bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
24a656665what do ya want for nothing?SHA-512164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737
6aa x 131Test Using Larger Than Block-Size Key - Hash Key FirstSHA-25660e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54

Case 6 uses a 131-byte key, longer than the 64-byte SHA-256 block. The key is hashed first and the 32-byte digest is then zero-padded, which is the rule this tool follows.

Choosing between SHA1, SHA256, SHA384 and SHA512

The choice of hash algorithm determines both security strength and output length. SHA-1 produces a 160-bit (20-byte) digest and is no longer recommended for new systems due to known collision weaknesses, though it remains common in legacy protocols like OAuth 1.0a. SHA-256 produces a 256-bit (32-byte) digest and is the most widely used variant for HMAC today, including in JSON Web Tokens (JWTs) and webhook signatures. See the SHA256 hash generator if you need a plain hash rather than an HMAC.

SHA-384 and SHA-512 use 128-byte blocks instead of 64-byte blocks and produce 48-byte and 64-byte digests respectively. They offer higher security margins and perform better on 64-bit processors. Use HMAC SHA512 when compliance requirements or threat models demand more than 256 bits of security.

Common uses for HMAC

HMAC is used wherever two parties share a secret key and need to verify that a message has not been altered. Common applications include:

  • Webhook verification: services like Stripe, GitHub and Slack sign outgoing payloads with HMAC SHA256 so receivers can confirm authenticity.
  • API request signing: AWS Signature Version 4 derives signing keys through a chain of HMAC SHA256 operations.
  • JSON Web Tokens: the HS256, HS384 and HS512 algorithms in JWTs are HMAC-based. Tools like the JWT decoder can inspect these tokens.
  • TOTP and HOTP: time-based and counter-based one-time passwords rely on HMAC SHA1 by default. See the HOTP generator for details.

Hex versus base64 encoding

The raw output of HMAC SHA256 is a sequence of 32 bytes. To transmit or store this value as text, it must be encoded. Hexadecimal encoding represents each byte as two characters (0-9, a-f), producing a 64-character string. Base64 encoding maps every three bytes into four printable characters, yielding a shorter 44-character string (with padding). Most APIs accept either format, but webhook documentation will specify which one to use. Always compare HMAC values using constant-time comparison to prevent timing attacks.

Worked examples

ExampleInputResult
RFC 4231 case 2 (SHA-256)Secret key: Jefe; Key format: text; Message: what do ya want for nothing?; Message format: text; Algorithm: sha256Hex: 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843; Base64: W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM=; Algorithm: HMAC-SHA256; Length: 32 bytes
RFC 4231 case 1 (SHA-512)Secret key: 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b; Key format: hex; Message: Hi There; Message format: text; Algorithm: sha512Hex: 87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854; Base64: h6p83qXvYZ1P8LQkGh1ssCN59OLOTsJ4etCzBUXhfN7aqDO31rinAgOLJ06uo/Tkvp2RTuth8XAuaWwgOhJoVA==; Algorithm: HMAC-SHA512; Length: 64 bytes
Webhook style signatureSecret key: whsec_test_secret; Key format: text; Message: {"event":"invoice.paid","id":"evt_123"}; Message format: text; Algorithm: sha256Hex: 5721ed99eb82b350024cb09432b13914d395bdbe68127428b97f8b35e4777b52; Base64: VyHtmeuCs1ACTLCUMrE5FNOVvb5oEnQouX+LNeR3e1I=; Algorithm: HMAC-SHA256; Length: 32 bytes
Message as hex bytesSecret key: key; Key format: text; Message: 00ff10; Message format: hex; Algorithm: sha1Hex: 67f33d41117a01fc3824072d0b7f31711124d8f2; Base64: Z/M9QRF6Afw4JActC38xcREk2PI=; Algorithm: HMAC-SHA1; Length: 20 bytes

FAQ

What is HMAC SHA256?

HMAC SHA256 is a message authentication code that uses the SHA-256 hash function combined with a secret key. It verifies both the integrity and authenticity of a message.

Is HMAC the same as a regular hash?

No. A regular hash like SHA-256 only ensures data integrity. HMAC adds a secret key, so only someone who knows the key can generate or verify the correct MAC.

Should I enter the key as text or hex?

Use text when your key is a passphrase or an API secret string, and hex when it is raw bytes such as a random 32-byte key. The same characters give different results in the two modes, so match what your other system does.

Can I use a short key for HMAC?

You can, but short keys reduce security. RFC 2104 recommends a key at least as long as the hash output: 32 bytes for SHA-256, 64 bytes for SHA-512.

Why does my HMAC output differ from another tool?

Check that you are using the same algorithm, the same byte representation for the key, and the same output format (hex or base64). Even a trailing newline in the message changes the result.

Is SHA-1 safe for HMAC?

HMAC-SHA1 is still considered secure for authentication because the HMAC construction mitigates the collision attacks that weaken plain SHA-1. However, SHA-256 is preferred for new projects.

Does this tool send my key to a server?

No. Hashing runs locally in your browser. Your key and message never leave your device.

Can I use HMAC to store passwords?

No. HMAC proves that a message came from someone holding a key. For password storage use a slow, salted function such as bcrypt (see the bcrypt generator), never a bare SHA-1 or MD5.