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.
The provider diagram shows how application code reaches algorithm implementations through the standard JCA and JCE APIs. section 4.3
