MD5

2017-11-06  本文已影响0人  昔年_小武

MD5介绍

private String MD5Code(String concated) {
        MessageDigest md5= null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update((concated.toString()).getBytes("UTF-8"));
            byte b[] = md5.digest();

            int i;
            StringBuffer buf = new StringBuffer("");

            for(int offset=0; offset<b.length; offset++){
                i = b[offset];
                if(i<0){
                    i+=256;
                }
                if(i<16){
                    buf.append("0");
                }
                buf.append(Integer.toHexString(i));
            }
            return buf.toString().toUpperCase();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
上一篇下一篇

猜你喜欢

热点阅读