通过MessageDigest加密
MessageDigest md = MessageDigest.getInstance("MD5");//创建一个MessageDigest的实力对象
md.update(password.getBytes());//将所需要加密的字符串password转化成Bytes数组,使用update进行加密
byte b[] = md.digest();//返回一个加密后的Byte数组
//以下过程将返回的加密后的Byte数组转换成32位的字符串
int i;
StringBuffer buf = new StringBuffer("");
HttpSession session = req.getSession(true);
System.out.println("储存的code" + session.getAttribute("code"));
System.out.println("获取code" + code);
System.out.println(session);
if (code.equalsIgnoreCase((String) session.getAttribute("code"))) {
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
String s = buf.toString();
使用springboot自带加密工具进行加密
String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());//password为需要加密的字符串
md5Password 为已加密的32位字符串