Comparing Message Digest Output of MD5 and SHA

This section a tutorial example on how to view and compare message digest output from two standard message digest algorithms MD5 and SHA.

The message digest output file contains binary data, which cannot be viewed directly. In order to see the digest data, I need to use my other program, HexWriter.java, to convert binary data to hex numbers. See chapter "Encoding Conversion" for details.

Here is how to look at the digest data in hex numbers, 16 bytes per line:

>javac HexWriter.java

>java -cp . HexWriter digest.sha digest_sha.hex

>type digest_sha.hex
87349C3BA487DC279E0AB7769F65CA22
E2747BE5

My second test is to see the digest data of the same input data, JcaMessageDigest.class, using MD5 algorithm:

>java -cp . JcaMessageDigest JcaMessageDigest.class digest.md5 MD5

MessageDigest Object Info:
Algorithm = MD5
Provider = SUN version 1.8
Digest Length = 16
toString = MD5 Message Digest from SUN, <initialized>

Message Digest Processing Info:
Number of input bytes = 2217
Number of output bytes = 16

>java -cp . HexWriter digest.md5 digest_md5.hex

type digest_md5.hex
B5DDC4E05A8F4048699A9532B9F31F0F

My third test is to see how the digest data changes if I add one byte to the input data:

>copy con dot.tmp
.^Z

>copy JcaMessageDigest.class JcaMessageDigest_1.class

>type dot.tmp >> JcaMessageDigest_1.class

>dir *.class
   2,217 JcaMessageDigest.class
   2,218 JcaMessageDigest_1.class

>java -cp . JcaMessageDigest JcaMessageDigest_1.class digest_1.md5 MD5

MessageDigest Object Info:
Algorithm = MD5
Provider = SUN version 1.8
Digest Length = 16
toString = MD5 Message Digest from SUN, <initialized>

Message Digest Processing Info:
Number of input bytes = 2218
Number of output bytes = 16

>java -cp . HexWriter digest_1.md5 digest_1_md5.hex

>type digest_1_md5.hex
31B82738B990A2ECDA63547B660CA0F0

A couple of interesting notes here:

Last update: 2014.

Table of Contents

 About This JDK Tutorial Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 Downloading and Installing JDK 1.6.2 on Windows

 Java Date-Time API

 Date, Time and Calendar Classes

 Date and Time Object and String Conversion

 Number Object and Numeric String Conversion

 Locales, Localization Methods and Resource Bundles

 Calling and Importing Classes Defined in Unnamed Packages

 HashSet, Vector, HashMap and Collection Classes

 Character Set Encoding Classes and Methods

 Character Set Encoding Maps

 Encoding Conversion Programs for Encoded Text Files

 Socket Network Communication

 Datagram Network Communication

 DOM (Document Object Model) - API for XML Files

 SAX (Simple API for XML)

 DTD (Document Type Definition) - XML Validation

 XSD (XML Schema Definition) - XML Validation

 XSL (Extensible Stylesheet Language)

Message Digest Algorithm Implementations in JDK

 java.security.MessageDigest - Message Digest MD5 and SHA

 JcaMessageDigest.java - Message Digest Sample Program

Comparing Message Digest Output of MD5 and SHA

 Private key and Public Key Pair Generation

 PKCS#8/X.509 Private/Public Encoding Standards

 Digital Signature Algorithm and Sample Program

 "keytool" Commands and "keystore" Files

 KeyStore and Certificate Classes

 Secret Key Generation and Management

 Cipher - Secret Key Encryption and Decryption

 The SSL (Secure Socket Layer) Protocol

 SSL Socket Communication Testing Programs

 SSL Client Authentication

 HTTPS (Hypertext Transfer Protocol Secure)

 Outdated Tutorials

 References

 PDF Printing Version