package com.zy.bms.utils; import java.security.MessageDigest; /** * MD5 字符串加密 * * @author chen_yi * Create on 2020/10/17 */ public class MD5Util { /** * MD5 字符串加密 * * @param plainText 加密字符串 * @return String 返回32位md5加密字符串 */ public static String MD5Encode(String plainText) { try { StringBuilder stringBuilder = new StringBuilder(); MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(plainText.getBytes()); byte[] bytes = messageDigest.digest(); int i; for (byte value : bytes) { i = value; if (i < 0) i += 256; if (i < 16) stringBuilder.append("0"); stringBuilder.append(Integer.toHexString(i)); } return stringBuilder.toString(); } catch (Exception e) { return null; } } }