JDK Tutorials - Herong's Tutorial Examples - Version 6.10, by Dr. Herong Yang
java.security.MessageDigest - Message Digest MD5 and SHA
This section describes 2 popular message digest algorithm, MD5 and SHA, implemented in JDK as part of the JCA (Java Cryptography Architecture) package.
What Is Message Digest? Message digest is a one-way hash function that takes arbitrary-sized data and outputs a fixed-length hash value.
Known message digest algorithms are:
Message digest is supported in JDK as part of the JCA (Java Cryptography Architecture) package, which has been included in JDK since 1.1:
In JCA, the java.security.MessageDigest class is an abstract class providing a link to implementation classes of message digest algorithms provided by various security package providers. Major methods in the MessageDigest class are:
getInstance() - Returns a message digest object of the specified algorithm from the implementation of the specified provider. If provider is not specified, the default implementation is used. This is a static method.
update() - Adds more data to the current message digest object for processing.
digest() - Returns the digest data of the input data processed so far in the current message digest object. It also removes the input data received in the object.
getAlgorithm() - Returns the algorithm name of the current message digest object.
getProvider() - Returns the provider as a provider object of the current message digest object.
See the next section for a sample program of using the MessageDigest class.
Last update: 2014.
Table of Contents