Imagine you receive a message claiming to be from your bank. It looks legitimate. But how do you know nobody tampered with it on the way to you?
A plain hash like SHA-256 doesn't help by itself. Anyone can hash a message â there is no secret involved. What you need is a way to prove the message was created (or at least approved) by someone who holds a shared secret key. That is exactly what HMAC does.
HMAC (Hash-based Message Authentication Code) was standardized in RFC 2104 (1997) by Hugo Krawczyk, Mihir Bellare, and Ran Canetti. It wraps any cryptographic hash function â SHA-256, SHA-3, whatever â with a key to produce a short tag. Send the message and its tag together. The receiver re-computes the tag with the same key; if the values match, the message is authentic and unmodified.
The magic: without the key you cannot compute a valid tag. Not because we made the hash function secret â it is still public SHA-256 â but because the key is woven into the computation in a way that makes forgery as hard as breaking the underlying hash.
Comments
Loading comments...