A secret key is confidential cryptographic material shared by authorized parties. Unlike a plain hash, a keyed value lets recipients check that data came from someone who knows the key and was not modified. section 4.5
The key creates a trust boundary: senders and receivers can compute a MAC, HMAC, or encryption result, while an attacker who sees the message cannot produce a valid keyed result without the key. section 4.5 section 4.7
Handle secret keys as security-critical material:
- Store application and HMAC keys in a secure credential store rather than hardcoding them or placing them in plain-text configuration files. section 2.2.1 section 4.7
- Generate cryptographic randomness with SecureRandom, not java.util.Random, when creating keys or related random values. section 5.3
- Use the key with a designed construction such as HMAC; do not replace HMAC with simple key-and-message concatenation. section 4.5 section 4.7
- Treat possession as the ability to impersonate an authorized party or decrypt protected data, depending on the construction. section 4.6 section 11.5.2
Protecting an ACME refunds file
The Warehouse application computes HMAC-SHA256 over refunds.json and sends the file with its expected value. The payments service recomputes the HMAC using the shared key, compares the values, and processes refunds only when they match. If an attacker changes the file without knowing the key, validation fails and no refunds are processed. section 4.6 section 4.7
Figure 4.8 The MAC is data added to the end of a message that the receiver can use to verify who sent the message and whether it was tampered with.
Trace how a sender computes a MAC from a message and secret key, then how a receiver recomputes it to detect tampering and authenticate the sender. section 4.5
Secret keys support several goals. HMAC and JWS-HS256 provide integrity and authentication; AES-GCM and JWE additionally provide confidentiality. Public-key systems can establish shared symmetric keys for later protected communication. section 4.6 section 11.5.2 section 7.5




