|
|
MD5 Hash of a an Array of BytesJeffrey P. Bigham |
|
Related ArticlesRelated 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!
import java.security.*;
...
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");
md5.update(my_bytes);
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. |
|
|
|
||