Cryptography at work
Message authentication code
A keyed hash: a tag computed from a message and a secret key, so only a holder of the key can produce or check it.
A message authentication code (MAC) is a tag computed from a message and a secret key. Anyone can compute a
[[cryptographic-hash|hash]], but only a holder of the key can make or check the tag, so a changed message is caught.
HMAC is the standard: openssl dgst -sha256 -hmac KEY file. Do not build hash(key + message): with SHA-256 a
length-extension attack appends data and fixes the tag without the key.
Read next
- Cryptographic hash A one-way function that turns any data into a short fixed-size fingerprint, so the same bytes always give the same digest and no one can find two inputs that share one.
- Integrity versus authenticity Integrity asks whether the bytes match a digest you trust; authenticity asks whether they came from who you think — a bare hash gives the first, a keyed hash or signature the second.