MD5 JAVA

private static String dumpBytes(byte[] bytes)
    {
        int i;
        StringBuffer sb = new StringBuffer();
        for (i = 0; i < bytes.length; i++)
        {
            if (i % 32 == 0 && i != 0)
            {
                sb.append("\n");
            }
            String s = Integer.toHexString(bytes[i]);
            if (s.length() < 2)
            {
                s = "0" + s;
            }
            if (s.length() > 2)
            {
                s = s.substring(s.length() - 2);
            }
            sb.append(s);
        }
        return sb.toString();
    }
    public static String MD5Encode(String origin)
    {
        String resultString = null;
        try
        {
            resultString = new String(origin);
            MessageDigest md = MessageDigest.getInstance("MD5");
            resultString = dumpBytes(md.digest(resultString.getBytes()));
        }
        catch (Exception ex)
        {
            throw new RuntimeException(ex);
        }
        return resultString;
    } 

Total views.

© 2013 - 2018. All rights reserved.

Powered by Hydejack v6.6.1