- 浏览: 1285526 次
- 性别:
- 来自: 常州
-
文章分类
- 全部博客 (499)
- java (101)
- linux (82)
- mysql (30)
- javascript (45)
- Oracle (12)
- ext (14)
- 虚拟机 (1)
- 搜索引擎 (2)
- struts2 (11)
- 设计模式 (9)
- nginx (17)
- tomcat (12)
- 随想 (10)
- spring (18)
- svn (1)
- flash (3)
- UML (1)
- 数据结构 (7)
- 算法 (2)
- 网摘 (9)
- 数据库 (15)
- ibatis (3)
- jquery (31)
- lucene (1)
- hibernate (14)
- Myeclipse (4)
- 线程 (7)
- jbpm (4)
- 重构 (1)
- mantis (3)
- MediaWiki (4)
- ExtMail (1)
- MDaemon (1)
- egit (1)
- dwr (7)
- sitemesh (2)
- mybatis (1)
- ico (1)
- hadoop (5)
- jsoup (1)
- urlrewrite (2)
- jstl (1)
- spring3 (2)
- aop (2)
- 定时器 (1)
- Quartz (2)
- apache (1)
- php (1)
- security (1)
- iptables (2)
- QQ (1)
- mysqldump (1)
- vim (1)
- memcached (4)
- jad (1)
- 微博 (1)
- html5 (1)
- css3 (1)
- httpclient (10)
- google (1)
- shortUrl (1)
- json (2)
- virtualBox (1)
- mantisBT (2)
- htmlunit (1)
- selenium (2)
- mail (1)
- 正则表达式 (4)
- html (3)
- css (2)
- jatoolsPrinter (1)
- 图片处理 (1)
- hql (1)
- webservice (1)
- 分词 (3)
- 短信 (1)
- VPS (1)
- 事务 (1)
- 广告 (1)
- 画廊 (1)
- git (3)
- github (1)
- openshift (1)
- 缓存 (1)
- web (3)
- android (3)
- c3p0 (1)
- 邮箱 (1)
- memcache (2)
- windows (2)
- js (14)
- 编辑器 (1)
- 打印 (1)
- centos (5)
- boneCP (1)
- 连接池 (1)
- sql (1)
- nosql (1)
- MongoDB (1)
- 浏览器 (1)
- node (1)
- node.js (1)
- backbone.js (1)
- lazyload (1)
- Switch Off (1)
- Titanium (1)
- 网站架构 (1)
- WebDriver (1)
- APJP (1)
- 代理 (1)
- comet (1)
- kendoui (1)
- UI (2)
- 互联网 (1)
- localStorage (1)
- 记录 (1)
- 微信 (2)
- Sphinx (1)
- netty (1)
- js,mvvm,Avalon (1)
- 安卓 (1)
- Tengine (1)
- 大数据 (1)
- 手机 (1)
- paypal (1)
- SaaS (1)
- gitlab (1)
- nodejs (1)
- React (1)
- shadowsocks (0)
- vpn (0)
- 验证码 (1)
- SSL (2)
- SEO (1)
- IntelliJ (1)
- 敏捷开发 (1)
- 项目管理 (1)
- 爬虫 (1)
- 正则 (1)
- owncloud (1)
- 云存储 (1)
- ajax (1)
- pjax (1)
- jdk (1)
- zookeeper (1)
- phantomjs (1)
- ELK (1)
- springcloud (1)
- IDEA (1)
- hexo (1)
- ss (1)
- letencrypt (1)
最新评论
-
peakandyuri:
这个是有BUG的,数字小体现不出来,数字大了就不对了,但是Ja ...
java十进制转换N进制并反转换的工具类 -
ginolai:
然后是相关配置:/etc/sysconfig/iptables ...
Linux中iptables设置详细 -
bzhao:
我测试没啥区别啊!
Thread.sleep()和Thread.currentThread().sleep()区别 -
zhl549342097:
match == false
Spring Security 3.1 中功能强大的加密工具 PasswordEncoder -
hellotieye:
renzhengzhi 写道drager 写道用jsoup后解 ...
jsoup select 选择器
好吧,这种加密机制很复杂,还是看下图比较好了解:
3.1.0版本中新的PasswordEncoder继承关系
而在Spring-Security 3.1.0 版本之后,Spring-security-crypto模块中的password包提供了更给力的加密密码的支持,这个包中也有PasswordEncoder接口,接口定义如下。
Public interface PasswordEncoder{ String encode(String rawPassword); Boolean matches(String rawPassword,String encodedPassword); }
定义了两个方法,encode方法是对方法加密,而match方法是用来验证密码和加密后密码是否一致的,如果一致则返回true。和authentication.encoding包中的PasswordEncoder接口相比,简化了许多。
位于org.springframeword.security.crypto.password包中的
StandardPasswordEncoder类,是PasswordEncoder接口的(唯一)一个实现类,是本文所述加密方法的核心。它采用SHA-256算法,迭代1024次,使用一个密钥(site-wide secret)以及8位随机盐对原密码进行加密。
随机盐确保相同的密码使用多次时,产生的哈希都不同; 密钥应该与密码区别开来存放,加密时使用一个密钥即可;对hash算法迭代执行1024次增强了安全性,使暴力破解变得更困难些。
和上一个版本的PasswordEncoder比较,好处显而易见:盐值不用用户提供,每次随机生成;多重加密————迭代SHA算法+密钥+随机盐来对密码加密,大大增加密码破解难度。
OK,了解了原理我们可以来测试一下:
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.StandardPasswordEncoder; /** * @author XUYI * Spring Security 3.1 PasswordEncoder */ public class EncryptUtil { //从配置文件中获得 private static final String SITE_WIDE_SECRET = "my-secret-key"; private static final PasswordEncoder encoder = new StandardPasswordEncoder( SITE_WIDE_SECRET); public static String encrypt(String rawPassword) { return encoder.encode(rawPassword); } public static boolean match(String rawPassword, String password) { return encoder.matches(rawPassword, password); } public static void main(String[] args) { System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?")); System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?")); System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?")); System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?")); System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?")); //但是把每次结果拿出来进行match,你会发现可以得到true。 } }
- spring-security-crypto-3.1.0.RELEASE.jar (40.1 KB)
- 下载次数: 101
发表评论
-
BoneCP-Spring详细配置
2013-08-03 21:09 1498BoneCP-Spring详细配置 <bean id ... -
spring的事务中程序控制事务成功失败(Transaction marked as rollback)
2013-01-22 15:32 20027A方法之外加有事务管理拦截器,在A方法中做一系列操作,操作 ... -
CXF WebService整合Spring[转载]
2012-11-02 18:52 1064转载:http://www.cnblogs.com/hoojo ... -
spring定时任务线程配置(quartz定时器)
2012-06-08 18:40 6203请注意是quartz定时器,不是timetask定时器! ... -
spring的定时器之Quartz
2012-02-24 16:11 2543Quartz是一个强大的企业级任务调度框架,Spring ... -
spring AOP支持文档
2012-02-22 17:56 15946.5 AspectJ切入点语法详解 6.5.1 ... -
Spring3.0中的AOP配置方法
2012-02-22 03:02 1875第一种配置方法:使用@AspectJ标签 在配置文件 ... -
spring中使用查询缓存
2011-12-31 21:01 3032由于使用的是spring3所以一下配置都基于spring3. ... -
spring AOP注释技巧-使用&&和!
2011-12-21 18:09 1500import org.apache.commons.lo ... -
spring3注解方式无法注入servlet和filter
2011-12-10 22:30 6808filter和servlet不受spring管理,所以不能依赖 ... -
spring3整合dwr3
2011-12-06 15:44 49171.web.xml中加入dwr配置如 ... -
spring整合struts2
2011-12-06 15:44 1401首先必须要spring2.5以上版本,其次必须加入strut ... -
详解Spring3基于Annotation的依赖注入实现
2011-12-04 18:28 1119简介: Spring 的依赖配置方式与 Spr ... -
[转]详解Spring3基于Annotation的依赖注入实现
2011-12-04 18:26 1793简介: Spring 的依赖配置方式与 Spring 框 ... -
spring基于注释的aop
2011-10-25 11:05 1111import java.util.Date; impo ... -
spring 1.2与spring 2.0中事务配置区别
2011-10-07 18:16 1159本文章比较了Spring自己带的例子:JPetStore ... -
spring定时任务
2011-08-02 09:32 1039http://softlife.iteye.com/blog/ ...
相关推荐
本文将深入探讨Spring Security 3.1的核心概念、主要功能以及如何在实际项目中应用。 1. **核心概念** - **Authentication(认证)**:验证用户身份的过程,包括用户名、密码等凭证的检查。 - **Authorization...
通过以上详细解析,可以看出Spring Security是一个非常强大且灵活的安全框架,它不仅能够满足基本的认证需求,还提供了丰富的高级特性,如权限管理、Remember-Me功能、session管理等。这对于构建安全可靠的企业级...
`BCryptPasswordEncoder`是Spring Security提供的强大工具,它自动化了盐值处理,为应用程序提供了更高级别的安全性。在实际开发中,应遵循最佳实践,使用`BCryptPasswordEncoder`对用户密码进行加密,以保护用户的...
Spring Security 提供了强大的安全功能,并能够灵活地与业务逻辑相结合。通过对Spring Security的理解与应用,不仅可以提升系统的安全性,还可以提高开发效率,减少维护成本。希望本手册能够帮助读者更好地掌握...
在SpringBoot项目中,首先需要添加`spring-boot-starter-security`和`spring-ldap-core`依赖。在`pom.xml`中加入以下代码: ```xml <groupId>org.springframework.boot <artifactId>spring-boot-starter-...