0
点赞
收藏
分享

微信扫一扫

MD5加盐加密工具类

爱动漫建模 2022-01-10 阅读 68

直接使用MD5加密,能被解密网站破解,因此在加密的时候可以加个盐值。工具类如下:

import org.apache.commons.codec.binary.Base64;
import java.security.MessageDigest;

public class MD5Utils {
	//加盐加密的盐值
	private static String saltValue = "suijishe88jfa2;f";

	/**
	 * 加盐加密
	 * @param strValue
	 * @return
	 * @throws Exception
	 */
	public static String getMD5Str(String strValue) throws Exception {
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		String newstr = Base64.encodeBase64String(md5.digest((strValue+saltValue).getBytes()));
		return newstr;
	}

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

相关推荐

0 条评论