发表于: 2017-05-04 22:10:45
1 1279
今天完成的事情:
学习了md5加密,尝试写了一个md5的工具类(虽然是照着例子写的.....)
public class MD5Util {
public static String stringToMD5(String string) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e){
e.printStackTrace();
}
//计算md5函数
md.update(string.getBytes());
//digest()最后确定返回md5 hash值
//Biginteger函数则将8位的字符串转换成16位的hex值,用字符串表示;得到字符串形式的hash值
return new BigInteger(1,md.digest()).toString(16);
}
}
学习了师兄的例子(登录的controller类的方法)
@RequestMapping(value = "/login.html",method = RequestMethod.POST)
public void loginaction(@RequestParam("username") String username, @RequestParam("password") String password,
HttpServletResponse httpServletResponse) {
String md5= MD5Util.stringToMD5(password);
if(userService.verification(username,md5)){
//待加密内容
long id=userService.selectToUsername(username).getId();
long creatDate=new Date().getTime();
String str = id+"="+creatDate;
//加密操作
byte[] result = DesUtil.desCrypto(str,"12345678");
//把加密的字节转换为16进制
String resules= TypeUtil.bytesToHexString(result);
Cookie cookie = new Cookie("token",resules);
cookie.setMaxAge(60*60*24*7);//保留7天
httpServletResponse.addCookie(cookie);
try {
httpServletResponse.sendRedirect("index.html");
} catch (IOException e) {
e.printStackTrace();
}
}else{
try {
httpServletResponse.sendRedirect("no.html");
} catch (IOException e) {
e.printStackTrace();
}
}
}
了解的任务5大概的学习流程
显示了解并依次学习DES,token,cookie,拦截器,然后在task4的项目中添加加密工具类然后,引用工具类对id和获取的登陆时间进行加密生成的密钥定义为token,然后将token加入cookie中,写好拦截器并通过cookie判断传入的token是否有效来甄别登录是否成功....(大概的流程理解了就是到操作的时候有点懵OTZ)
明天计划的事情:
开始写md5加密id和时间
遇到的问题:
暂无
收获:
理解了加盐的意义....就是为了让密钥安全性更高.....
评论