You are about to wire an API that signs its requests, and the documentation shows an example signature. Most developers skim past it and start debugging against the live service, where every failure could belong to either side. There is a faster order. That example is a test with the answer printed next to it. Reproduce it first, with your own setup, and you walk into the integration already knowing your half works.
This guide shows how to run that known-answer test with the free HMAC Generator on Ovatly, how to read a failure, and where the boundary sits between a proven signer and a working integration.
Contents
- Quick answer
- Why documentation examples carry known answers
- What a passed test actually proves
- How to run the test, step by step
- Worked example: the fox vector, digit for digit
- When the example passes but the API still says no
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Take the published example from the documentation, or the classic vector with the key key and the message The quick brown fox jumps over the lazy dog. Sign it with HMAC-SHA-256. The hex result must be exactly f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8. If it is, your wiring is correct. If not, the bug is in the wiring, and the usual suspects, in order, are the key encoding, a trailing newline, and the algorithm choice. The HMAC Generator runs this test in under a minute, on your device.
Why documentation examples carry known answers
HMAC is deterministic. The same key, message and hash function always produce the same signature, on every machine, in every language. That makes a published example unusually powerful: it is not an illustration, it is a specification you can execute.
Providers publish these vectors so integrators can separate two questions that live debugging tangles together. Is my signing correct? And am I signing the right bytes? The known-answer test settles the first question completely, in private, without rate limits or a support ticket. Only then does the second become worth asking, and by then you ask it with a tool you trust.
What a passed test actually proves
Matching the published value proves three things at once. Your key reaches the hash as the bytes the documentation intends, not as a hex string read as text or a text key read as hex. Your message reaches the hash byte for byte, with no trailing newline added on the way. And the SHA-256 in your setup is the same SHA-256 as in the specification.
It also proves something about your tooling. The generator shows results in hex and Base64, the same bytes in two encodings, so a passed test confirms you are comparing in the format the receiver specifies. Many integrations fail at exactly that last step, with correct signing judged wrong by a mismatched comparison. What the test does not prove matters too, and the section on real APIs below covers it: your signer can be perfect while the bytes your application chooses to sign are the wrong ones.
How to run the test, step by step
- Open the HMAC Generator. Everything runs on your device, so the example key never leaves your machine.
- Paste the message exactly:
The quick brown fox jumps over the lazy dog. Check that no trailing newline came along; if in doubt, type the sentence by hand. - Enter the secret key as the single word
key, as plain text. - Pick SHA-256. The generator offers SHA-256, SHA-384 and SHA-512, and the published answer for this vector belongs to SHA-256 alone.
- Click Compute HMAC and compare the hex output character by character with the expected value. Verification of any HMAC works this way: sign again and compare, because the signature cannot be decrypted.
- If the value differs, change exactly one thing, the key reading, the message, or the algorithm, and compute again, until the change that fixes it identifies the fault.
Worked example: the fox vector, digit for digit
Inputs:
Key: key
Message: The quick brown fox jumps over the lazy dog
Algorithm: SHA-256
Expected output, in hex:
f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
Run those inputs through the generator and the output matches, digit for digit. That match is the whole test. Now break it deliberately. Add one trailing newline to the message: the signature changes completely, with no partial resemblance to the expected value. Restore the message and instead enter the key as its hex form, 6b6579, typed as plain text: the signature changes completely again, because the signer now uses six bytes instead of three. Two lessons follow. A wrong HMAC never looks almost right, so do not grade your result by eye. And each single-byte cause produces the same total failure, which is why you change one variable at a time.
When the example passes but the API still says no
A passed known-answer test moves the investigation, it does not end it. If the live service still rejects your signatures, your signing is proven and the message is the suspect. Real schemes rarely sign the bare payload. They sign a construction: a timestamp joined to the body, a method and path joined to a hash, headers in a fixed order. Sign a slightly different construction and the bytes differ, so the signature fails, correctly.
The other classic is the travelling payload. Your code parses the incoming JSON and signs the re-serialised output, whose key order and spacing differ from the raw bytes the sender signed. Sign the raw body exactly as it arrived.
Limitations and honest tradeoffs
HMAC authenticates; it does not encrypt. Anyone with the shared key can sign as well as verify, so a passed test says nothing about secrecy, only about agreement between key, message and signature. A random key of 32 bytes or more remains the sound default for HMAC-SHA-256 in a real system, whatever toy key a test vector uses.
The generator processes everything on your device, and still, never sign production secrets on a machine you do not trust. The known-answer test exists precisely so real secrets are unnecessary while you verify behaviour. A published vector also cannot prove the standard fits your threat model, or rescue a key that was too short or shared too widely.
Common mistakes
- Skipping the example and debugging live. Every failure then has two possible owners. Run the known answer first and halve the search space.
- Copying the message with a trailing newline. The paste looks identical and signs differently. Type the message by hand when a result surprises you.
- Testing with the real key. There is usually no published answer for it, so a mismatch teaches nothing.
- Comparing against the Base64 output. The expected value in most documentation is hex. Same bytes, different encoding, false alarm.
- Assuming a pass ends the work. The test proves the signer. The construction you sign still has to match the scheme exactly.
FAQs
What is a known-answer test for HMAC? It is a published example where the key, the message and the correct signature are all given. Run your own setup with those exact inputs and it must produce that exact signature. If it does, your key handling, encoding and algorithm choice are proven in one step. If not, the wiring is wrong and you can find the fault in isolation.
Which example should I test with? The classic published vector uses the key key and the message The quick brown fox jumps over the lazy dog. With HMAC-SHA-256 the correct result in hex is f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8. Any correct HMAC implementation in any language or tool must return exactly that value for those inputs.
My result is close but not identical. What does that mean? HMAC results are never close. One different byte in the key or the message produces a completely unrelated signature, so a wrong value tells you the inputs were not what you believed, without saying which byte differed. Work the suspects in order: key encoding, trailing newline, algorithm, changing one thing at a time.
The published example works but the real API still rejects my signatures. Why? Because the example proves your signing, not the API's message format. Real systems sign specific bytes: often a timestamp plus the raw request body, exactly as sent. Sign a re-serialised payload, or leave out a header the scheme includes, and the signature fails even though your HMAC itself is correct.
Can I test with my real API key instead of the example? You can, but you learn less and risk more. With a real key you usually have no published answer to compare against, so a wrong result proves nothing about which side is wrong. Test with the example key first.
Conclusion
Five minutes with a published example buys certainty that hours of live debugging cannot: your key handling, your message bytes and your algorithm are right, proven against an answer nobody disputes. When failures remain after that, they live in the construction you sign, and you can hunt them with a trusted tool in hand. The encoding trap that causes most of those wiring failures is covered in our companion guide, HMAC Mistakes: Using the Wrong Encoding for the Key. For more guides in this series, see our Security and Privacy guides.
References
- RFC 2104, HMAC: Keyed-Hashing for Message Authentication: https://www.rfc-editor.org/rfc/rfc2104
- RFC 4231, Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512: https://www.rfc-editor.org/rfc/rfc4231