【工具类】MD5Utils

2022-10-25 16:11:00 浏览数 (1)

MD5Utils

代码语言:javascript复制
import org.apache.commons.codec.binary.Base64;

import java.security.MessageDigest;

public class MD5Utils {

	/**
	 * @Description: 对字符串进行md5加密 
	 */
	public static String getMD5Str(String strValue) throws Exception {
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		String newstr = Base64.encodeBase64String(md5.digest(strValue.getBytes()));
		return newstr;
	}

	public static void main(String[] args) {
		try {
			String md5 = getMD5Str("imooc");
			System.out.println(md5);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

实例:

代码语言:javascript复制
users.setPassword(MD5Utils.getMD5Str(users.getPassword()));

0 人点赞