HMAC
HMAC is a keyed message authentication code constructed from a cryptographic hash function and a secret key to authenticate data and verify its integrity.
Software Security for Developers
HMAC is a keyed message authentication construction that combines a secret key with a cryptographic hash function to provide message integrity and authenticity.
- How it is used
- Protects files, request payloads, API calls, and protocol messages against tampering while authenticating parties sharing a secret.
- How deep it goes
- Defines the construction and implementation choices, but deliberately defers the internal key-mixing algorithm and its mathematics.
- Examples
- Uses an ACME refunds.json transfer, Java Mac code, validation logic, and comparisons with plain hashes and RSA signatures.
- What you can do after
- Apply it via Java's Mac and SecretKeySpec APIs to compute and validate HMAC-SHA-256 values before processing data.
Hacking Cryptography
HMAC is a keyed-hash message authentication construction that produces an integrity and authentication tag from a key and message.
- How it is used
- Authenticates messages and detects modification when a shared secret must protect an API request or protocol message.
- How deep it goes
- Explains the nested equation, key normalization, ipad/opad transformations, and attacks against simpler MACs.
- Examples
- Uses a forged bank transaction, Flickr-style API authentication, RADIUS, AWS API signatures, and HMAC-MD5 as concrete cases.
- What you can do after
- Evaluate MAC designs and choose HMAC instead of direct secret-prefix or secret-suffix hashing for authentication.
Secure APIs
HMAC is a message authentication code construction that combines a hash function with a secret key to authenticate data.
- How it is used
- Authenticates API requests and JWTs by combining a shared secret with a hash-derived digest or signature.
- How deep it goes
- Defines shared-key request authentication and JWT signing inputs, but does not descend into HMAC internals or implementation code.
- Examples
- Uses an HS256 JWT whose signature covers the base64url-encoded header and payload joined by a dot.
- What you can do after
- Evaluate/understand how HMAC authenticates API requests and signs JWTs without encrypting their claims.
Real-World Cryptography
HMAC is a standardized keyed-hash message authentication code constructed from a cryptographic hash function and a secret key.
- How it is used
- Protects message integrity and authenticity when communicating parties share a secret key.
- How deep it goes
- Explains keyed tag generation, verification, replay limits, length-extension risks, and constant-time comparison without detailing HMAC internals.
- Examples
- Demonstrates Rust sender and receiver functions using HMAC-SHA-256, message tags, and verification.
- What you can do after
- Apply it via Rust to authenticate messages, verify tags safely, and avoid direct SHA-256 MAC constructions.
Also covered in
What to know first
- hash functionA hash function is a deterministic function that maps input data to a hash value, typically of fixed size, for uses such as lookup, indexing, comparison, or integrity checking.
- message authentication codeA message authentication code is a keyed cryptographic value generated from a message to verify its integrity and authenticity.
- SHA-2SHA-2 is a standardized family of cryptographic hash algorithms that produces fixed-length digests, including SHA-224, SHA-256, SHA-384, and SHA-512.
- authenticationAuthentication is the process of verifying the claimed identity of a user, service, device, or other entity.
Related concepts
- message authentication codekind of · A message authentication code is a keyed cryptographic value generated from a message to verify its integrity and authenticity.
- hash functionuses · A hash function is a deterministic function that maps input data to a hash value, typically of fixed size, for uses such as lookup, indexing, comparison, or integrity checking.
- SHA-256uses · SHA-256 is a standardized cryptographic hash function in the SHA-2 family that maps input data to a fixed-length 256-bit digest.
- collision attackcontrasts with · A collision attack is a cryptanalytic technique that seeks two distinct inputs producing the same hash output.
- cryptographic hashuses · A cryptographic hash is a fixed-length digest computed deterministically from input data by a function designed to resist practical preimage, second-preimage, and collision attacks.
- digital signaturecontrasts with · A digital signature is a cryptographic value associated with data that can be verified to provide evidence of the data’s origin and integrity.
Questions about HMAC
What is HMAC?
HMAC is a keyed message authentication code constructed from a cryptographic hash function and a secret key to authenticate data and verify its integrity.
Which Manning books explain HMAC?
Software Security for Developers, Hacking Cryptography, Secure APIs and Real-World Cryptography.
What should I know before learning HMAC?
Manning books that teach HMAC usually introduce hash function, message authentication code, SHA-2 and authentication first.
What is the difference between HMAC and collision attack?
HMAC is a keyed message authentication code constructed from a cryptographic hash function and a secret key to authenticate data and verify its integrity. A collision attack is a cryptanalytic technique that seeks two distinct inputs producing the same hash output.
What is HMAC a kind of?
HMAC is a kind of message authentication code. A message authentication code is a keyed cryptographic value generated from a message to verify its integrity and authenticity.
What is HMAC also called?
HMAC is also called hash-based message authentication code.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



