package com.mindprod.example;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* example use of MD5 with java.security.MessageDigest Test MD5 digest computation
* <p/>
* composed with IntelliJ IDEA
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0, 2004-06-07
* @since 2004-06-07
*/
public final class TestMD5
{
/**
* demonstrate how to compute an MD5 message digest requires Java 1.4+
*
* @param args not used
* @throws UnsupportedEncodingException if 8859_1 not supported.
* @throws NoSuchAlgorithmException if MD5 not supported.
*/
public static void main( String[] args ) throws UnsupportedEncodingException, NoSuchAlgorithmException
{
byte[] theTextToDigestAsBytes =
"The quick brown fox jumped over the lazy dog's back"
.getBytes( "8859_1");
MessageDigest md = MessageDigest.getInstance( "MD5" );
md.update( theTextToDigestAsBytes );
byte[] digest = md.digest();
System.out.println( "Algorithm used:" + md.getAlgorithm() );
System.out.println( digest.length );
for ( byte b : digest )
{
System.out.print( Integer.toHexString( b & 0xff ) + " " );
}
}
}