1. 程式人生 > 其它 >MD5一般加密方法

MD5一般加密方法

 // MD5加密
    private static String standardMD5(String s){
        char[]  hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
        try
        {
            byte[] strTemp = s.getBytes("gbk");
            MessageDigest mdTemp = MessageDigest.getInstance(("m" + hexDigits[13] + hexDigits[5]).toUpperCase());
            mdTemp.update(strTemp);
            
byte[] md = mdTemp.digest(); int j = md.length; char[] str = new char[j * 2]; int k = 0; for (int i = 0; i < j; i++) { byte byte0 = md[i]; str[(k++)] = hexDigits[(byte0 >>> 4 & 0xF)]; str[(k
++)] = hexDigits[(byte0 & 0xF)]; } return new String(str).toUpperCase(); } catch (NoSuchAlgorithmException ignored) {} catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return null; }