Spring Security中的MD5盐值加密
在 spring Security 文档中有这么一句话: "盐值的原理非常简单,就是先把密码和盐值指定的内容合并在一起,再使用md5对合并后的内容进行演算,这样一来,就算密码是一个很常见的字符串,再加上用户名,最后算出来的md5值就没那么容易猜出来了。因为攻击者不知道盐值的值,也很难反算出密码原文。"
问题如何理解这句话: "先把密码和盐值指定的内容合并在一起,再使用md5对合并后的内容进行演算". 例如, 在 applicationContext-security.xml 文件中的配置如下:
<authentication-provider user-service-ref="userDetailsService">
<password-encoder hash="md5">
<!-- 将每个用户的username作为盐值 -->
<salt-source user-property="username"/>
</password-encoder>
</authentication-provider>
假设用户名是 Tom, 密码为 123456, 那么在数据库中存放的值应该是什么?
通过查看 Spring Security 的 org.springframework.security.providers.encoding.BasePasswordEncoder 类可知 Spring Security 通过如下方式来匹配在数据库中已经被盐值加密的密码:
protected String mergePasswordAndSalt(String password, Object salt, boolean strict) {
if (password == null) {
password = "";
}
if (strict && (salt != null)) {
if ((salt.toString().lastIndexOf("{") != -1) || (salt.toString().lastIndexOf("}") != -1)) {
throw new IllegalArgumentException("Cannot use { or } in salt.toString()");
}
}
if ((salt == null) || "".equals(salt)) {
return password;
} else {
return password + "{" + salt.toString() + "}";
}
}
即通过 password + "{" + salt.toString() + "}" 中方式把 "密码和盐值指定的内容合并在一起". 所以对于用户名是 Tom, 密码为 123456 的用户在数据库中存放的密码应该为对 "123456{Tom}" md5 验算后的值: 610c492873b994f96f93e342a56bcd68
Spring Security中的MD5盐值加密的更多相关文章
- shiro密码的比对,密码的MD5加密,MD5盐值加密,多个Relme
有具体问题的可以参考之前的关于shiro的博文,关于shiro的博文均是一次工程的内容 密码的比对 通过AuthenticatingRealm的CredentialsMatcher方法 密码的加密 ...
- c# MD5盐值加密
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptograph ...
- MD5盐值加密
加密思路 思路解析:(数据解析过程基于16进制来处理的,加密后为16进制字符串) 加密阶段: 对一个字符串进行MD5加密,我们需要使用到MessageDigest(消息摘要对象),需要一个盐值(sal ...
- shiro 密码的MD5盐值加密
- c# MD5及盐值加密
using System;using System.Collections.Generic;using System.Linq;using System.Security.Cryptography;u ...
- SpringBoot整合shiro-MD5盐值加密
为什么要进行密码加密? 在我们的日常生活中,许多人有着在不同网站上使用相同密码的坏习惯(包括我也是qaq),假如应用程序或服务器出现漏洞,数据被窃取,用户的明文密码直接被暴露给黑客.显然后果将不堪设想 ...
- 一个密码经过多次MD5加密能否提高安全性?Java MD5盐值加解密
什么是MD5? MD5(Message Digest Algorithm 5,信息摘要算法5),是计算机广泛使用的摘要算法(又称哈希算法)之一.MD5是将一段信息,通过其不可逆的字符串变换算法,产生了 ...
- 浅谈使用spring security中的BCryptPasswordEncoder方法对密码进行加密与密码匹配
浅谈使用springsecurity中的BCryptPasswordEncoder方法对密码进行加密(encode)与密码匹配(matches) spring security中的BCryptPass ...
- Spring Security 中的 Bcrypt
最近在写用户管理相关的微服务,其中比较重要的问题是如何保存用户的密码,加盐哈希是一种常见的做法.知乎上有个问题大家可以先读一下: 加盐密码保存的最通用方法是? 对于每个用户的密码,都应该使用独一无二的 ...
随机推荐
- Mysql提升大数据导入速度的绝妙方法
一.对于Myisam类型的表,可以通过以下方式快速的导入大量的数据. ALTER TABLE tblname DISABLE KEYS; loading the data A ...
- android布局中显示隐藏动画
android 在布局中提供属性,能简单的加入动画效果,例如以下: <LinearLayout ... animateLayoutChanges="true" ... /&g ...
- do while 循环和while循环的差别
do while 循环和while循环的差别 1.do while循环是先运行循环体,然后推断循环条件,假设为真,则运行下一步循环,否则终止循环. while循环是先推断循环条件,假设条件为真则 ...
- 遗传奥秘的伟大揭秘者:J.Watson
J.Watson的近照: 人们公认,揭秘生命体的遗传奥秘(DNA)是二十世纪最伟大的科技成果之中的一个,或许就是人类最伟大的科技进步(而不是"之中的一个"). 上世纪是人类做出伟大 ...
- android AppWidget的使用以及利用TimerTask实现widget的定时更新
第一步:首先是Widget的定义声明: 在资源文件下的xml目录中建立文件example_appwidget_info.xml: <?xml version="1.0" en ...
- MFC C++ 获取外网IP地址
#include <afxinet.h> //GB2312 转换成 Unicode wchar_t* GB2312ToUnicode(const char* szGBString) { U ...
- C# 监控Windows睡眠与恢复
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; private void SystemEvents_PowerModeC ...
- Redis通过命令行进行配置
redis 127.0.0.1:6379[1]> config set requirepass my_redis OK redis 127.0.0.1:6379[1]> config ge ...
- angularjs1-7,供应商
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- angularjs1-过滤器
<!DOCTYPE html> <html> <body> <header> <meta http-equiv="Content-Typ ...