java md5加密 使用log4j.core.util.NameUtil.md5

导包:

import static org.apache.logging.log4j.core.util.NameUtil.md5;

demo

String md5Str = md5(需加密的字符串);

源码

public static String md5(String string) {
    try {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        digest.update(string.getBytes());
        byte[] bytes = digest.digest();
        StringBuilder md5 = new StringBuilder();
        byte[] arr$ = bytes;
        int len$ = bytes.length;

        for(int i$ = 0; i$ < len$; ++i$) {
            byte b = arr$[i$];
            String hex = Integer.toHexString(255 & b);
            if (hex.length() == 1) {
                md5.append('0');
            }

            md5.append(hex);
        }

        return md5.toString();
    } catch (Exception var9) {
        return string;
    }
}

 

上一篇:谷歌身份认证 Python实现


下一篇:ZooKeeper学习之路(五)—— ACL权限控制