final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', git
'a', 'b', 'c', 'd', 'e', 'f' }; 數組
try { ide
byte[] strTemp = passWord.getBytes(); 加密
MessageDigest mdTemp = MessageDigest.getInstance("MD5"); spa
mdTemp.update(strTemp); md5
byte[] md = mdTemp.digest(); 字符串
int j = md.length; get
char str[] = new char[j * 2]; string
int k = 0; it
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
md5Password=new String(str); // 以前改成str.toString(); 出現每次加密都不同狀況,array.tostring()是將字符數組改成字符串數組
} catch (Exception e) {
System.out.println("md5加密異常");
}