Java MD5 32位加密

    public static String md5(String plaintext) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plaintext.getBytes());
            byte bytes[] = md.digest();

            int c;

            StringBuffer buf = new StringBuffer("");
            for (int index = 0; index < bytes.length; index++) {
                c = bytes[index];
                if (c < 0){
                    c += 256;
                }
                if (c < 16){
                    buf.append("0");
                }
                buf.append(Integer.toHexString(c));
            }
            return buf.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
发布了172 篇原创文章 · 获赞 64 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/WeiHao0240/article/details/102939629