liveBook · Manning

MessageDigest API

As explained in Software Security for Developers

The MessageDigest API is the Java API for obtaining and applying implementations of cryptographic hash functions.

MessageDigest is Java’s API for applying cryptographic hash functions. A hash converts arbitrary-size input into a fixed-size output, making it useful for checking whether data has changed. Obtain an implementation with MessageDigest.getInstance() and choose a standardized algorithm name such as SHA-256 or SHA3-256. section 4.3

Hashing a file

Read refunds.json, call MessageDigest.getInstance("SHA3-256").digest(data), and format the resulting bytes as hexadecimal. The same file produces the same digest, such as 542b49a04073502046b0de5751d5f7a9afe7c1ff2d63524c0863233a53de0c14, so another copy can be compared for integrity. section 4.3

Choose algorithms carefully:

  • Use SHA-2 or SHA-3 for new applications; retain MD2, MD5, and SHA-1 only for historical data. section 4.3
  • The JCA routes the standard API call to a provider’s implementation, keeping application code independent of the implementation. section 4.3
Figure 4.6 Application code calls the standard JCA and JCE APIs, making the code independent of the crypto algorithm implementation. The JCA and JCE layer routes calls to a provider’s implementation. Java 11-based OpenJDK ships with 13 providers out of the box.
figure

The provider diagram shows how application code reaches algorithm implementations through the standard JCA and JCE APIs. section 4.3

How Software Security for Developers covers it

How deep it goes
Demonstrates obtaining a provider-backed implementation, hashing file bytes, formatting output, and selecting secure algorithms without explaining hash internals.
Examples
Hashes refunds.json with SHA3-256 and compares the stable hexadecimal digest across repeated runs or different files.
What it assumes
Assumes basic Java application development while explaining hash outputs, providers, algorithm names, and file-digest workflow.
What you can do after
Apply hashing via Java’s MessageDigest API and recognize safer algorithm choices for new applications.
How it connects
Connects cryptographic hash functions with the JCA, JCE, security providers, and SHA-2 and SHA-3 algorithms.

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.