导包:
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; } }