废话不多说,直接上代码。jdk自带的加密工具。
public class MD5Util { private MD5Util() { } public static String md5(String sourceStr) { byte[] secretBytes = null; try { secretBytes = MessageDigest.getInstance("md5").digest(sourceStr.getBytes()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("异常!"); } String md5code = new BigInteger(1, secretBytes).toString(16);// // for (int i = 0; i < 32 - md5code.length(); i++) { md5code = "0" + md5code; } return md5code; } }
文章来源: https://blog.csdn.net/qq_33029793/article/details/92379193