MD5加密算法

来源:互联网 发布:mysql 5.6.25安装 编辑:程序博客网 时间:2024/05/22 04:30
// 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();    }
0 0