generateDigest("jinghuajuanke","MD5");java
public static String generateDigest(String info, String algorithm) {
String infoDigest = "";
try {web
java.security.MessageDigest alga = java.security.MessageDigest.getInstance(algorithm);spa
alga.update(info.getBytes());.net
byte[] digesta = alga.digest();orm
infoDigest = byte2hex(digesta);字符串
} catch (Exception e) {
e.printStackTrace();
}
return infoDigest;
}
/**
* 二行制轉化成十六進制字符串
*
* @param b
* @return
*/
public static String byte2hex(byte[] b) {
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
/*if (n < b.length - 1)
hs = hs + ":";*/
}
return hs.toUpperCase();
}get