liveBook · Manning

Cryptographic key

As explained in Software Security for Developers

A secret key is confidential cryptographic material shared by authorized parties to compute or verify keyed security values.

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.
figure

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

How Software Security for Developers covers it

How deep it goes
Explains keyed verification, storage risks, and Java implementations, while deferring the full key-agreement problem to public-key mechanisms.
Examples
Demonstrates refunds.json HMAC validation, AES-GCM encryption, Nimbus JWS signing, and JWE encryption and decryption.
What it assumes
Assumes basic messages and applications, then builds distinctions between hashes, keyed authentication, encryption, and public-key key agreement.
What you can do after
Apply it via HMAC, AES-GCM, JWS, or JWE while validating inputs and protecting keys from configuration and code exposure.
How it connects
Connects secret keys to MAC, HMAC, AES-GCM, JWS, JWE, TLS, RSA, and ECC.

Also explained in

Compare how 5 books explain cryptographic key →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Security for Developers. The section links point to the parts of the book it draws on.