zoukankan      html  css  js  c++  java
  • MD5

    import java.io.UnsupportedEncodingException;

    import java.math.BigInteger;

    import java.security.MessageDigest;

    import java.security.NoSuchAlgorithmException;

    public class MD5 {

        public static String hex2asc(String str) {

            String[] s = str.trim().split("\\x");

            // System.out.println(s.length);

            StringBuffer sb = new StringBuffer();

            for (String sItem : s) {

                // System.out.println(sItem);

                sb.append(sItem);

            }

            int len = sb.toString().length();

            // String data = null;

            StringBuffer sb1 = new StringBuffer();

            for (int i = 0; i < len; i += 2) {

                int x = Integer.parseInt(sb.toString().substring(i, i + 2), 16);

                char ss = (char) x;

                System.out.println(x + "::" + ss + "转换后->" + MD5.md5(String.valueOf(ss)));

                sb1.append(String.valueOf(ss));

            }

            return sb1.toString();

        }

        public static String md5(String plainText) {

            byte[] secretBytes = null;

            try {

                try {

                    secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes("UTF-8"));

                } catch (UnsupportedEncodingException e) {

                    System.out.println("不存在UTF-8编码");

                    e.printStackTrace();

                }

            } catch (NoSuchAlgorithmException e) {

                throw new RuntimeException("没有md5这个算法!");

            }

            String md5code = new BigInteger(1, secretBytes).toString(16);

            for (int i = 0; i < 32 - md5code.length(); i++) {

                md5code = "0" + md5code;

            }

            if(md5code.length()==31)

            {

                     md5code = "0" + md5code;

            }

            return md5code;

        }

             public static void main(String[] str)

             {

                       String persion ="";

                      System.out.println(MD5.md5("account870108card4096709300491381mobile15808907777type25f7af31ccb3544659373715bcc320b96").toUpperCase());

             }

       

    }

  • 相关阅读:
    Compression algorithm (deflate)
    tcpip数据包编码解析(chunk and gzip)_space of Jialy_百度空间
    What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
    gzip压缩算法: gzip 所使用压缩算法的基本原理
    Decompressing a GZip Stream with Zlib
    Frequently Asked Questions about zlib
    how to decompress gzip stream with zlib
    自己动手写web服务器四(web服务器是如何通过压缩数据,web服务器的gzip模块的实现)
    What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
    C语言抓http gzip包并解压 失败 C/C++ ChinaUnix.net
  • 原文地址:https://www.cnblogs.com/chinaifae/p/10400472.html
Copyright © 2011-2022 走看看