开发者

Java MD5 hash, how can i do? [duplicate]

This question already has answers here: 开发者_如何学JAVA Closed 12 years ago.

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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜