public final static String MD5(String s) {
byte[] btInput = s.getBytes();
MessageDigest mdInst = null;
try {
mdInst = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
System.out.println("NoSuchAlgorithmException:md5");
e.printStackTrace();
return null;
}
mdInst.update(btInput);
byte[] md = mdInst.digest();
StringBuffer sb = new StringBuffer();
for (byte i = 0; i < md.length; i++) {
int val = ((int) md[i]) & 0xff;
if (val < 16) sb.append("0");
sb.append(Integer.toHexString(val));
}
return sb.toString();
}
java MD5
最新推荐文章于 2020-05-08 22:09:54 发布