How to generate an MD5 hash from a String in Java

The MD5 hash can be generated in java using DigestUtils from org.apache.commons.codec.digest.

Call the following method:

org.apache.commons.codec.digest.DigestUtils.md5Hex( "value" );

Create the following java file:

public class MD5 {

	public static void main(String[] argv){

		String value = "this is a test";
		
		String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex( value );

		System.out.println( "The md5 of \""+ value + "\" is: " + md5 );
     }
}

The output will be:

The md5 of "this is a test" is:
54b0c58c7ce9f2a8b551351102ee0938

The MD5 hash is very simple and can be easily cracked using rainbow tables it preferable to use more secure methods like sha256.

References:

Java 8
Online tool generating MD5
Raimbow table to revert MD5

Recent Comments