Java MD5 hash, how can i do? [duplicate]
Possible Duplicates:
Generate MD5 hash in Java using Java to get a file's md5 checksum?
Hi boys,
how can i generate a MD5 from a file using java?
Here's one way.
public static String md5(String s) {
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(s.getBytes());
return new BigInteger(1, md5.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
}
}
精彩评论