md5 hashing and MD5Digest revisited
Please Login to Remove!
In case anyone else falls down the hole of how to get a normal md5
string in Java:-
static public String sampleMD5Digest( byte[] plainText, byte[] digestData ) throws CryptoException, IOException
{
// Create an instance of the digest algorithm
MD5Digest digest = new MD5Digest();
// Create the digest output stream for easy use
DigestOutputStream digestStream = new DigestOutputStream( digest, null );
// Write the text to the stream
digestStream.write( plainText );
// Copy the digest data to the digestData byte array and
// return the length
digest.getDigest( digestData, 0 );
String md5s = new String("");
for (int i=0;i <16 ; i++)
{
if (((digestData[i]) & 0xff) < 16) //toHexString returns single digit!!
md5s +="0";
md5s += Integer.toHexString((digestData[i]) & 0xff);
}
return md5s;
}
|