@@ -0,0 +1,1899 @@
+package main.java8.tricks;%0A%0Aimport java.security.MessageDigest;%0A%0Aimport static java.lang.System.out;%0A%0A/**%0A * Title : main.java8.tricks %3Cbr%3E%0A * Description :%0A *  %3Cp%3E%0A *  %3Cul%3E %0A *      %3Cli%3E%0A *  %3C/ul%3E%0A * @author chile%0A * @version 1.0%0A * @date 2018/3/20 17:40%0A */%0Apublic class StringToMD5 %7B%0A%0A    /**%0A     * %E5%8D%81%E5%85%AD%E8%BF%9B%E5%88%B6%E4%B8%8B%E6%95%B0%E5%AD%97%E5%88%B0%E5%AD%97%E7%AC%A6%E7%9A%84%E6%98%A0%E5%B0%84%E6%95%B0%E7%BB%84%0A     */%0A    private final static String%5B%5D HEX_DIGITS = %7B %220%22, %221%22, %222%22, %223%22, %224%22, %225%22,%0A            %226%22, %227%22, %228%22, %229%22, %22a%22, %22b%22, %22c%22, %22d%22, %22e%22, %22f%22 %7D;%0A%0A    /**%0A     * get MD5 string%0A     * @param originString origin string%0A     * @return MD5 with hex (length : 32)%0A     */%0A    private static String getMD5(String originString) %7B%0A        if (originString != null)%7B%0A            try %7B%0A                MessageDigest md = MessageDigest.getInstance(%22MD5%22);%0A                byte%5B%5D results = md.digest(originString .getBytes());%0A                String resultString = byteArrayToHexString(results);%0A                return resultString.toUpperCase();%0A            %7D catch (Exception ex) %7B%0A                ex.printStackTrace();%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A    /**%0A     * %E8%BD%AC%E6%8D%A2%E5%AD%97%E8%8A%82%E6%95%B0%E7%BB%84%E4%B8%BA16%E8%BF%9B%E5%88%B6%E5%AD%97%E4%B8%B2%0A     *%0A     * @param b  %E5%AD%97%E8%8A%82%E6%95%B0%E7%BB%84%0A     * @return %E5%8D%81%E5%85%AD%E8%BF%9B%E5%88%B6%E5%AD%97%E4%B8%B2%0A     */%0A    private static String byteArrayToHexString(byte%5B%5D b) %7B%0A        StringBuilder resultSb = new StringBuilder();%0A        for (byte aB : b) %7B%0A            resultSb.append(byteToHexString(aB));%0A        %7D%0A        return resultSb.toString();%0A    %7D%0A%0A    /**%0A     * %E5%B0%86%E4%B8%80%E4%B8%AA%E5%AD%97%E8%8A%82%E8%BD%AC%E5%8C%96%E6%88%9016%E8%BF%9B%E5%88%B6%E5%BD%A2%E5%BC%8F%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%0A     * @param b a byte%0A     * @return the hex digit for the byte%0A     */%0A    private static String byteToHexString(byte b) %7B%0A        int n = b;%0A        if (n %3C 0) %7B%0A            n = 256 + n;%0A        %7D%0A        int d1 = n / 16;%0A        int d2 = n %25 16;%0A        return HEX_DIGITS%5Bd1%5D + HEX_DIGITS%5Bd2%5D;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        String s = %22heheda%22;%0A        String md5 = getMD5(s);%0A        out.println(md5);%0A    %7D%0A%0A%7D%0A

Generate md5 string (length : 32) for a string.