大家好,又见面了,我是你们的朋友全栈君。
package com.pibigstar.common.utils;
import java.security.MessageDigest;
/** * MD5加密工具类 * @author pibigstar * */
public class MyMD5Util {
//盐,用于混交md5
private static final String slat = "&%5123***&&%%$$#@";
public static String encrypt(String dataStr) {
try {
dataStr = dataStr + slat;
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(dataStr.getBytes("UTF8"));
byte s[] = m.digest();
String result = "";
for (int i = 0; i < s.length; i++) {
result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
package com.pibigstar.common.utils;
import org.springframework.util.DigestUtils;
import com.pibigstar.common.Constant;
/** * MD5工具类 * @author pibigstar * */
public class MD5Util {
//盐,用于混交md5
private static final String slat = "&%5123***&&%%$$#@";
/** * 生成md5 * @param seckillId * @return */
public static String getMD5(String str) {
String base = str +"/"+slat;
String md5 = DigestUtils.md5DigestAsHex(base.getBytes());
return md5;
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/156731.html原文链接:https://javaforall.cn