ManticMoo.COM All Articles Jeff's Articles
Jeffrey P. Bigham

MD5 Hash of a an Array of Bytes

Jeffrey P. Bigham

Related Ads

Below is all you need to know to calculate the MD5 hash of an array of bytes in Java. It's actually surprisingly simple. Go Java!



MessageDigest md5;
byte[] digest = new byte[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

byte[] my_bytes;

try {
md5 = MessageDigest.getInstance("MD5");
digest = md5.digest();
} catch (NoSuchAlgorithmException e) {
  System.err.println("Couldn't find MD5 algorithm");

After running this code, the byte array digest will contain the MD5 hash of the data in my_bytes.

Jeffrey P. Bigham
ManticMoo.COM All Articles Jeff's Articles