随笔都是学习笔记
随笔仅供参考,为避免笔记中可能出现的错误误导他人,请勿转载。

 

 // 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;
    }

 

posted on 2022-12-06 15:28  时间完全不够用啊  阅读(70)  评论(0编辑  收藏  举报