MD5介紹
- 只有16位和32位的兩種穆刻;
- 將一個(gè)字符串轉(zhuǎn)化成一個(gè)MD5的32位,如下:
private String MD5Code(String concated) {
MessageDigest md5= null;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update((concated.toString()).getBytes("UTF-8"));
byte b[] = md5.digest();
int i;
StringBuffer buf = new StringBuffer("");
for(int offset=0; offset<b.length; offset++){
i = b[offset];
if(i<0){
i+=256;
}
if(i<16){
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
return buf.toString().toUpperCase();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者