Message Digests

The JCA provides support for the generation of message digests via the java.security.MessageDigest class. This class uses the standard factory class design, so to create a MessageDigest instance, use the getInstance() method with the desired algorithm name and optional provider as parameters.

Once created use the various update() methods to process the message data and then finally call the digest() method to calculate the final digest. At this point the instance may be reused to calculate a digest for a new message.

   MessageDigest digest = MessageDigest.getInstance("SHA");

   byte[] msg = "The message".getBytes();
   digest.update(msg);

   byte[] result = digest.digest();