Online HMAC generator

HMAC tags a message with a key. The algorithms here are MD5, SHA-1, SHA-256, SHA-384, and SHA-512. The key and the message are both read as UTF-8 bytes. The key is not decoded as hex first. The tag has the same length as that hash: 32, 40, 64, 96, or 128 hex characters. The same key, the same message, and the same algorithm always produce the same tag. Concatenating the key and the message and then hashing that string is a different value. HMAC does not hide the message, and it has no salt, so it is not a password store.

What a key changes in a hash of the same UTF-8 bytes

HMAC mixes a key into a hash. The algorithms here are MD5, SHA-1, SHA-256, SHA-384, and SHA-512. The key and the message are both the UTF-8 bytes of the text that was typed. The key is not decoded as hex first. The tag has the length of that hash: 32, 40, 64, 96, or 128 hex characters, which is 24, 28, 44, 64, or 88 Base64 characters. SHA-384 is 48 bytes, so its Base64 form has no padding character.

The key key and the message abc produce the HMAC-SHA-256 tag 9c196e32dc0175f86f4b1cb89289d6619de6bee699e4c378e68309ed97a1a6ab. In Base64 that same tag is nBluMtwBdfhvSxy4konWYZ3mvuaZ5MN45oMJ7Zehpqs=. SHA-256 of abc alone starts with ba7816bf. SHA-256 of the concatenation keyabc is 1141e2212b08bb07b3c9558bb7a90f4a99b1c6f0c97e970c279df64e7f0875ed. Neither string is the HMAC tag. The same key, the same message, and the same algorithm always repeat the tag, because there is no salt.

A key shorter than the block is padded with zero bytes. MD5, SHA-1, and SHA-256 use a 64-byte block. SHA-384 and SHA-512 use a 128-byte block. A key longer than the block is hashed once, and that digest is then padded. The inner pad byte is 36 hex and the outer pad byte is 5c hex. The message stays readable. HMAC does not encrypt it. A password store wants a slow hash, which is the subject of bcrypt. A bare digest is hash digest. The hex spelling of a tag is hex encode and decode.

How the key, the block, and the UTF-8 bytes decide the tag

Why HMAC-MD5 through HMAC-SHA-512 write 32, 40, 64, 96, and 128 hex characters

  1. MD5 is 128 bits, SHA-1 is 160, SHA-256 is 256, SHA-384 is 384, and SHA-512 is 512. Two hex characters are one byte.
  2. Those lengths are 32, 40, 64, 96, and 128 hex characters. Base64 of the same tags is 24, 28, 44, 64, and 88 characters.
  3. HMAC-SHA-512 of key and abc starts with 3926a207. It is not HMAC-SHA-256 with extra characters stuck on the end.

Why hashing the key and the message concatenated is not HMAC

  1. HMAC hashes the inner pad mixed with the key, then hashes the outer pad mixed with that inner digest and the message.
  2. SHA-256 of the six characters keyabc is 1141e2212b08bb07b3c9558bb7a90f4a99b1c6f0c97e970c279df64e7f0875ed. HMAC-SHA-256 of key and abc starts with 9c196e32.
  3. Putting the message first, or inserting a colon between the key and the message, is a third string. The tag moves either way.

Why the key is the UTF-8 bytes of the text, not a hex decoding

  1. The three letters key are the bytes 6b 65 79. The six characters 6b6579 are the bytes of those digits and letters.
  2. HMAC-SHA-256 of the key 6b6579 and the message abc is cdd1e9711b2f531b9459a6a04b988d405f138bff447236e33d556b56d9e5106f. That is not the tag of the key key.
  3. A newline is the byte 0A. The key key plus a newline, with the message abc, starts the HMAC-SHA-256 tag at e5166670.

Why HMAC neither hides the message nor stores a password

  1. The message is an input to the tag. The tag does not replace the message, and anyone who can read the message can still read it.
  2. The same key and the same message always yield the same tag. There is no salt, and these hashes are fast enough to try in bulk.
  3. A password store wants a slow hash and a new salt each time. A tag with no key is only a digest, and it cannot show who produced it.

Where the published tag and the typed key quietly disagree

The three letters abc under the three-letter key key

HMAC-SHA-256 of the key key and the message abc is 9c196e32dc0175f86f4b1cb89289d6619de6bee699e4c378e68309ed97a1a6ab. HMAC-SHA-1 of that same pair is 4fd0b215276ef12f2b3e4c8ecac2811498b656fc, 40 hex characters. HMAC-MD5 is d2fe98063f876b03193afb49b4979591, 32 hex characters. The letters did not change between the three algorithms. Only the hash inside the construction changed. The Base64 form of the SHA-256 tag is nBluMtwBdfhvSxy4konWYZ3mvuaZ5MN45oMJ7Zehpqs=.

A key that was pasted as the hex spelling of itself

The word key is three bytes, 6b 65 79. The text 6b6579 is six bytes, the characters 6, b, 6, 5, 7, and 9. HMAC-SHA-256 of that six-character key and the message abc is cdd1e9711b2f531b9459a6a04b988d405f138bff447236e33d556b56d9e5106f. A check that expected the three-byte key will not match. The hex spelling of a byte string is the subject of hex encode and decode. The tag here is a function of the bytes that were typed.

A login table that stored one HMAC-SHA-256 and called it enough

A shared key plus HMAC-SHA-256 of a password is the same tag for every copy of that password, and it is fast to recompute. There is no salt and no iteration count. A bare SHA-256 of the password is a different mistake, and it is the subject of hash digest. A password store wants a slow hash: bcrypt. HMAC can show that a message still matches a key. It does not hide the message, and it does not replace the password.

Common questions

What is the HMAC-SHA-256 of abc with the key key?
The key key and the message abc produce 9c196e32dc0175f86f4b1cb89289d6619de6bee699e4c378e68309ed97a1a6ab. That is 64 hex characters, lowercase, with no spaces and no 0x prefix. The Base64 form of the same 32 bytes is nBluMtwBdfhvSxy4konWYZ3mvuaZ5MN45oMJ7Zehpqs=. SHA-256 of abc alone starts with ba7816bf, so the key is doing real work. The key secret and the message hello produce 88aab3ede8d3adf94d26ab90d3bafd4a2083070c3bcce9c014ee04a443847c0b.
How long is an HMAC-SHA-256 tag in hex and in Base64?
SHA-256 is 32 bytes. Hex writes two characters per byte, so the tag is 64 characters. Base64 writes three bytes as four characters and adds one padding character, so the tag is 44 characters and ends with one equals sign. HMAC-SHA-384 is 48 bytes, 96 hex characters, and 64 Base64 characters with no padding. HMAC-SHA-512 is 64 bytes, 128 hex characters, and 88 Base64 characters.
How is HMAC different from SHA-256 of the same text?
SHA-256 of abc is ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad. Anyone who can see abc can recompute that digest. HMAC-SHA-256 of the key key and the message abc starts with 9c196e32. Someone who does not have the key cannot recompute the tag from the message alone. The construction is also not SHA-256 of the concatenation. SHA-256 of keyabc starts with 1141e221.
Does HMAC encrypt the message?
No. HMAC produces a fixed-length tag. The message is still the message. A reader who can see the message can read every byte of it. The tag can show that those bytes still match a key. It cannot put the bytes back if they were never stored, and it cannot conceal them if they were stored beside the tag. Encryption is a different construction, with a ciphertext that replaces the message.
Is the key 6b6579 the same key as the word key?
No. The word key is the three bytes 6b 65 79. The text 6b6579 is six characters, and those characters are hashed as themselves. HMAC-SHA-256 of the key 6b6579 and the message abc is cdd1e9711b2f531b9459a6a04b988d405f138bff447236e33d556b56d9e5106f. HMAC-SHA-256 of the key key and the same message starts with 9c196e32. A hex string is text until something decodes it into bytes.
Why does one extra newline in the key change the whole tag?
A newline is the byte 0A. The key key is three bytes. The key key followed by a newline is four bytes. HMAC-SHA-256 of that four-byte key and the message abc starts with e5166670, not with 9c196e32. The same thing happens if the newline is on the message instead of the key. The tag is a function of both byte strings, not of the words as a person reads them.
Can an HMAC tag be turned back into the message?
No. The tag has a fixed length, and many messages can be paired with a key to reach those bits. The 64 hex characters of HMAC-SHA-256 do not store the length of the message or a path back to it. A match means the key and the message bytes were the same under that algorithm. It does not reveal the message, and it does not reveal the key.
Is HMAC-SHA-512 just a longer HMAC-SHA-256?
No. SHA-256 uses a 64-byte block and 32-bit words. SHA-512 uses a 128-byte block and 64-bit words. The pad construction is the same shape, and the hash inside it is not. HMAC-SHA-256 of key and abc starts with 9c196e32 and is 64 hex characters. HMAC-SHA-512 of the same pair starts with 3926a207 and is 128 hex characters. Cutting or stretching one tag does not produce the other.