springSecurity 密码md5+salt配置

密码进行md5加密,并且带salt值。

例如username:name password:pass  salt为username

则明文密码为  pass{name}  括弧中为salt对应的username,再对明文密码进行加密


springSecurity配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  <authentication-manager  alias= "authenticationManager"  >
     <authentication-provider ref= "authenticationProvider" >  </authentication-provider>
  </authentication-manager>
     
    <beans:bean id= "authenticationProvider"  class = "org.springframework.security.authentication.dao.DaoAuthenticationProvider" >  
     <beans:property name= "userDetailsService"  ref= "myUserDetailService"  />  
     <beans:property name= "passwordEncoder"  ref= "passwordEncoder" /> 
     <beans:property name= "saltSource"  ref= "saltSource" /> 
   </beans:bean>
   
   <beans:bean id= "passwordEncoder"   class = "org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
<beans:bean id= "saltSource"  class = "org.springframework.security.authentication.dao.Reflec tionSaltSource" >
     <beans:property name= "userPropertyToUse"  value= "username" />
</beans:bean>


authenticationProvider的配置中加入passwordEncoder与saltSource两个属性

到此配置就结束了


同时,springSecurity提供了Md5PasswordEncoder类实现MD5加密

1
2
3
Md5PasswordEncoder md5 =  new  Md5PasswordEncoder(); 
String result = md5.encodePassword( "user" "user" );
System.out.println(result);

md5.encodePassword两个参数中,前一个为password,后一个为salt盐值


同时,网站http://md5jiami.51240.com/ 也提供了在线加密的功能


     本文转自布拉君君 51CTO博客,原文链接:http://blog.51cto.com/5148737/1615981,如需转载请自行联系原作者






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值