MD5 in Java

I wrote an implementation of the MD5 hash routine in Java originally in 1995. You'll find that implementation here. Note however that since 1995 a lot of progress has occured in the Java language and its associated libraries, as well as cryptographic hash function security. If you are planning to use a cryptographic hash function in a security-critical (during the whole required secure lifetime of the use of the hash results), do not use MD5, instead use SHA1.

That is not however to say you can not use MD5. Just do not use it anymore in new security-critical systems. Otherwise, just go ahead. Besides, who am I to tell you what to do?

Usage

The md5.jar file is a library. You need to add it to the classpath either through environmental variable CLASSPATH or using java runtime flag -classpath - or some other mechanism.

For example, try:

java -classpath md5.jar \
fi.iki.santtu.md5.MD5TestSuite

to run the test-suite from within the archive file.

Class Hierarchy

Originally the class was just in no package space. When looking around at the home page rework how people have used the class I found that someone had plonked it in fi.iki.santtu.md5 package. Well, why not! That is a good, persistent package name. So the classes are in fi.iki.santtu.md5.

The fi.iki.santtu.md5 package contains the following classes:

MD5
This is the main class implementing the MD5 algorithm. When calculating digests, this is usually the only package you really need.
MD5TestSuite
This package is a self-contained Java application. It can be used to verify the correctness of the implementation. It uses the test vectors from RFC 1321.
MD5InputStream
Subclass of java.io.FilterInputStream calculating the MD5 hash of the input stream on the fly.
MD5OutputStream
Subclass of java.io.FilterOutputStream calculating the MD5 hash of the output stream on the fly.

History

Originally I wrote the MD5 class in 1995 for a Java applet, related to the MERCUS project in Helsinki University of Technology, Computing Science department. I put the source code and class files available on a website under the LGPL license. And then forgot about it.

It seems however that quite a few people have found the class useful. Useful enough to send me bug reports and optimizations! When I reworked my web pages in 2003 I finally got the impetus to integrate these contributions as well as update the sources and class files to a bit more recent Java version (J2SE 1.4.1).

If you for some peculiar reason do need old (1995) versions, I've put them also available for download.

Version History

Version 1.9: Interim release. Classes have been moved to fi.iki.santtu.md5 package, an md5.jar creation added, but various optimizations and patches provided by the Java community are pending integration (e.g. for 2.0 release).
 fi-iki-santtu-md5-1.9.tar.gz, 29 kB

Version 1.0 aka before versioning: Original implementation circa 1995-1996. I have posthumously named this honorable release as version 1.0. The file below is the old-old release just slightly repackaged. It does not live in any package hierarchy itself.
 MD5-1.0.tar.gz, 11 kB

Fact sheet

Requires: Java runtime and/or compiler
License: LGPL
Last active: 2003

 fi-iki-santtu-md5-1.9.tar.gz, 29 kB