MD5加密算法

// md5加密
public static String md5(String s) {
try {
MessageDigest algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(s.getBytes("UTF-8"));
return toHexString(algorithm.digest());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
 private static String toHexString(byte[] byteArray) {
    StringBuffer md5StrBuff = new StringBuffer();

    for (int i = 0; i < byteArray.length; i++) {
        if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
        md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
        else
        md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
    }
    return md5StrBuff.toString();
    }

你可能感兴趣的:(android,加密,MD5)