public class MD5 {
public static String getMD5(String val) throws NoSuchAlgorithmException{
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(val.getBytes());
byte[] m = md5.digest();//加密
return getString(m);
}
private static String getString(byte[] b){
StringBuffer sb = new StringBuffer();
for(int i = 0; i < b.length; i ++) {
int temp = b[i];
if (temp < 0) temp += 256;
if (temp < 16) sb.append("0");
sb.append(Integer.toHexString(temp));
}
// 32位
return sb.toString();
// 16位
// return sb.toString().substring(8, 24);
}
}
Android的MD5加密,32位与16位
最新推荐文章于 2023-12-14 11:25:58 发布