HMAC Generator
Published Updated
Compute an HMAC with SHA-256, SHA-384 or SHA-512 for typed text or a whole file, with the secret read as UTF-8. The result is lowercase hex of 64, 96 or 128 characters, and the RFC 4231 Jefe example matches its published value.
A published test vector
RFC 4231 lists test vectors for HMAC with the SHA-2 family. Its second case uses the key Jefe and the data what do ya want for nothing?, both plain text, so they can be typed into this page. Google Chrome 156 returned the published values:
Jefe, case 2
| Algorithm | Start of the hex output | Length |
|---|---|---|
| SHA-256 | 5bdcc146bf60754e6a042426089575c7... | 64 |
| SHA-384 | af45d2e376484031617f78d2b58a6b1b... | 96 |
| SHA-512 | 164b7a7bfcf819e2e395fbe73b56e0a3... | 128 |
A key and a message with accents, café for both, also matched Node's output.
One byte changes everything
An HMAC covers every byte, so a trailing newline is enough to produce an unrelated value. With the key key and SHA-256, the text message gives 6e9ef29b75ff..., the same text plus a line feed gives 62b5378a72e1..., and a file holding the text plus a carriage return and line feed gives adaccb84a55a....
That is why a webhook check fails when a framework re-serialises the body. MDN's HMAC reference lists SHA-256, SHA-384 and SHA-512 as the digests behind this page, with SHA-1 supported but discouraged. Use File mode to hash the exact bytes you saved.
The seven RFC 4231 cases in three browsers
All seven test cases of RFC 4231 were run through the page's own form in Google Chrome 158, Firefox 155 and Playwright's WebKit build (not the Safari app), each with SHA-256, SHA-384 and SHA-512. A match means the measured output equalled the published value for all three sizes (for case 5, which the RFC truncates to 128 bits, the start of the output); every other case failed for all three. Keys were placed in the key box by the test script.
| Case | Key | Data | Chrome 158 | Firefox 155 | The WebKit build |
|---|---|---|---|---|---|
| 1 | 20 bytes of 0x0b | Hi There | Match | Key box left empty | Match |
| 2 | Jefe | what do ya want for nothing? | Match | Match | Match |
| 3 | 20 bytes of 0xaa | 50 bytes of 0xdd (File mode) | No match | No match | No match |
| 4 | 25 bytes, 0x01 to 0x19 | 50 bytes of 0xcd (File mode) | No match: the line feed and carriage return became spaces | No match: the box kept only the tab | No match: the line feed and carriage return became spaces |
| 5 | 20 bytes of 0x0c | Test With Truncation | Match | Key box left empty | Match |
| 6 | 131 bytes of 0xaa | A 54-character sentence | No match | No match | No match |
| 7 | 131 bytes of 0xaa | A 152-character sentence | No match | No match | No match |
Cases 3, 6 and 7 cannot match on this page: their key bytes are 0xaa, and a key typed as text is turned into UTF-8, where no single character is that one byte. Entered as the character ª, each byte becomes the two bytes C2 AA; a key of 20 such characters matched Node.js 22.23.1 when Node was given those UTF-8 bytes. Cases 1 and 5 use control characters as keys, which Firefox 155 removed, leaving the key box empty. Case 4's key holds a line feed and a carriage return, which the single-line key box does not keep.
Line breaks in the text box and the key box
The HTML standard's textarea rules give a script the text box's value with every line break as a line feed. When the test script entered message followed by a carriage return and a line feed into Text mode, Chrome 158 and Firefox 155 did that, and the page signed message plus a line feed (62b5378a72e1... with the key key and SHA-256). The WebKit build kept the carriage return when the text was inserted the way a paste is, and gave the carriage-return value, adaccb84a55a.... In File mode, a test file with carriage returns and line feeds was signed byte for byte in all three browsers (each value matched Node.js), so the same bytes saved as a file give that carriage-return value, and a body that must match a server byte for byte is safest signed as a file.
The key box is a password field, and the same standard does not let users insert a line feed or carriage return into it. When the test script typed ke, a line break and y, Chrome 158, Firefox 155 and the WebKit build each kept ke y, with a space.
Signing a large file
Time from pressing the button to the result, measured once per cell on random files on one Mac, SHA-256 / SHA-512. Every result equalled Node.js's crypto module for the same file.
| File | Chrome 158 | Firefox 155 | The WebKit build |
|---|---|---|---|
| 1 MB | 58 / 66 ms | 45 / 52 ms | 53 / 43 ms |
| 10 MB | 81 / 197 ms | 259 / 72 ms | 97 / 119 ms |
| 50 MB | 167 / 212 ms | 262 / 347 ms | 288 / 185 ms |
Signing text or a file
Step 1
Choose Text or File
Text is encoded as UTF-8. A file is read as raw bytes, so a trailing newline or a line-ending change affects the result.
Step 2
Enter the secret and algorithm
The secret is also read as UTF-8 text. Pick SHA-256, SHA-384 or SHA-512, then press the generate button.
Step 3
Copy the hex
The signature is shown as lowercase hex, 64, 96 or 128 characters long. Copy puts it on the clipboard.
How the inputs are read
- Empty text gives the message Enter some text first. A missing secret gives Enter a secret key first.
- Changing the mode, the text, the file, the key or the algorithm clears the old result, also while a large file is still being signed, so the result on screen always belongs to the inputs shown.
- RFC 2104 calls a key shorter than the hash output strongly discouraged, because it lowers the security strength.
- To sign a JWT instead, JWT Generator builds the header and payload around the same call.
HMAC questions
Why does my server compute a different HMAC?
Check three things: the exact bytes, since a trailing newline or CRLF changes everything; the secret, which this page uses as typed characters; and the output form, because some APIs expect base64 and this shows hex.
Can I enter a hex or base64 key?
Not as bytes. Whatever you type is encoded as UTF-8 text, so the hex string abcd is used as four characters, not two bytes. Keys that are raw binary cannot be entered.
Why are SHA-1 and MD5 missing?
MDN lists SHA-1 among the digests Web Crypto accepts for HMAC, but marks it as vulnerable, and the page offers only SHA-256, SHA-384 and SHA-512. MD5 is not on that list at all. A service that requires HMAC-SHA1 or HMAC-MD5 needs another tool.
Is there a file size limit?
No limit is set in the code. The whole file is read into memory before it is signed, so a very large file depends on the tab's available memory. An empty file is rejected on upload.
What about a very long secret?
Any length works. Under RFC 2104, a key longer than the hash's block size is hashed first. The results for keys of 63, 64, 65, 128, 129 and 200 characters matched Node's crypto module.
Is the secret or my data uploaded?
No. Signing happens through the browser's Web Crypto API, so the secret, the text and any file are processed in your browser; this page does not upload them.
Why don't RFC 4231 test cases 3, 6 and 7 match?
Their keys are bytes of value 0xaa, and the key box is read as UTF-8 text, where no single character is that byte. Typing ª gives the two bytes C2 AA, a different key. Case 2, whose key and data are plain text, matched with all three hash sizes in Chrome 158, Firefox 155 and the WebKit build.
Does a Windows line ending in the text box change the HMAC?
It can. In Chrome 158 and Firefox 155 the text box handed the page a line feed for each CR LF, so message followed by CR LF was signed as message followed by LF (with the key key and SHA-256, a value starting 62b5378a72e1). The WebKit build kept the CR when the text was inserted like a paste. File mode signed a CR LF test file byte for byte in all three browsers, so message plus CR LF saved as a file gives the value starting adaccb84a55a.
Can the secret key contain a line break?
No. The key box is a single-line field. A line break typed into it became a space in Chrome 158, Firefox 155 and the WebKit build, so ke, a line break and y was used as ke y.
How long does a 50 MB file take?
From the button press to the result, 167 ms with SHA-256 in Chrome 158, 262 ms in Firefox 155 and 288 ms in the WebKit build, on one Mac. The whole file is read into memory first.