MySQL MD5 and Java MD5 not equal
This can be shortened to a one-liner by using the utility classes from the Apache Commons Codec library (http://commons.apache.org/codec)
String md = org.apache.commons.codec.digest.DigestUtils.md5hex("whatever");
replace
sb.append( ( int )( 0x00FF & b ) );
if( i+1 <bytes.length ) {
sb.append( "-" );
}
by
String hex = Integer.toHexString((int) 0x00FF & b);
if (hex.length == 1) sb.append("0");
sb.append( hex );
Try encoding in base 16. Just to get you started... 94 in base 16 is 5E.
**Edit:**Try changing your getString method:
private static String getString( byte[] bytes )
{
StringBuffer sb = new StringBuffer();
for( int i=0; i<bytes.length; i++ )
{
byte b = bytes[ i ];
String hex = Integer.toHexString((int) 0x00FF & b);
if (hex.length() == 1)
{
sb.append("0");
}
sb.append( hex );
}
return sb.toString();
}