客户的Java平台,使用了spring框架自带的MD5方法来加密,我的是C#下面的MD5加密方法,我这边的加密方法只要穿字符串就行了,不要密钥,结果他那边Java平台里的MD5加密是有密钥的而且使用的是动态密钥,然后查了一下Spring的加密方式.
Acegi 对于密码提供三种方式:明文及不采用任何加密方式、MD5加密方式、哈希算法加密方式。
只需要在DAO的认证管理器中分别加入一下对应一下配置:
第一种:不使用任何加密方式的配置
Java代码
- <bean
id= "daoAuthenticationProvider"class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> -
"userDetailsService"<property name= ref= "userDetailsService"/> -
-
<!-- 明文加密,不使用任何加密算法, 在不指定该配置的情况下,Acegi默认采用的就是明文加密 --> -
<!-- -
"passwordEncoder"><property name= -
class="org.acegisecurity.providers.encoding.PlaintextPasswordEncoder"><bean -
"ignorePasswordCase"<property name= value= "true"></property> -
</bean> -
</property> -
--> - </bean>
第二种:MD5方式加密
Java代码
- <bean
id= "daoAuthenticationProvider"class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> -
"userDetailsService"<property name= ref= "userDetailsService"/> -
-
"passwordEncoder"><property name= -
class="org.acegisecurity.providers.encoding.Md5PasswordEncoder"><bean -
false<!-- 表示:生成 32位的Hex版,这也是encodeHashAsBase64的, trueAcegi 默认配置; 24位的Base64版表示:生成 --> -
"encodeHashAsBase64"<property name= value= "false"/> -
</bean> -
</property> - </bean>
第三种:使用MD5加密,并添加全局加密盐
Java代码
- <bean
id= "daoAuthenticationProvider"class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> -
"userDetailsService"<property name= ref= "userDetailsService"/> -
-
"passwordEncoder"><property name= -
class="org.acegisecurity.providers.encoding.Md5PasswordEncoder"><bean -
"encodeHashAsBase64"<property name= value= "false"/> -
</bean> -
</property> -
-
<!-- 对密码加密算法中使用特定的加密盐及种子 --> -
"saltSource"><property name= -
class="org.acegisecurity.providers.dao.salt.SystemWideSaltSource"><bean -
"systemWideSalt"<property name= value= "acegisalt"/> -
</bean> -
</property> - </bean>
第四种:使用MD5加密,并添加动态加密盐
Java代码
- <bean
id= "daoAuthenticationProvider"class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> -
"userDetailsService"<property name= ref= "userDetailsService"/> -
-
"passwordEncoder"><property name= -
class="org.acegisecurity.providers.encoding.Md5PasswordEncoder"><bean -
"encodeHashAsBase64"<property name= value= "false"/> -
</bean> -
</property> -
-
<!-- 对密码加密算法中使用特定的加密盐及种子 --> -
"saltSource"><property name= -
<!-- 通过动态的加密盐进行加密,该配置通过用户名提供加密盐, 通过UserDetails的getUsername()方式 --> -
class="org.acegisecurity.providers.dao.salt.ReflectionSaltSource"><bean -
"userPropertyToUse"<property name= value= "getUsername"/> -
</bean> -
</property> - </bean>
第五种:使用哈希算法加密,加密强度为256
Java代码
- <bean
id= "daoAuthenticationProvider"class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> -
"userDetailsService"<property name= ref= "userDetailsService"/> -
-
"passwordEncoder"><property name= -
class="org.acegisecurity.providers.encoding.ShaPasswordEncoder"><bean -
"256"<constructor-arg value= /> -
"encodeHashAsBase64"<property name= value= "false"/> -
</bean> -
</property> - </bean>
Java代码
- <bean
id= "daoAuthenticationProvider"class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> -
"userDetailsService"<property name= ref= "userDetailsService"/> -
-
"passwordEncoder"><property name= -
class="org.acegisecurity.providers.encoding.ShaPasswordEncoder"><bean -
"SHA-256"<constructor-arg value= /> -
"encodeHashAsBase64"<property name= value= "false"/> -
</bean> -
</property> - </bean>
Java代码
- package
com.brofe.acegi; -
- import
org.acegisecurity.providers.encoding.Md5PasswordEncoder; - import
org.acegisecurity.providers.encoding.ShaPasswordEncoder; -
-
- public
class TestPasswordEncoder { -
-
publicstatic void main(String[] throwsargs) Exception { -
-
//md5(); 使用简单的MD5加密方式 -
-
//sha_256(); 使用256的哈希算法(SHA)加密 -
-
//sha_SHA_256(); 使用SHA-256的哈希算法(SHA)加密 -
-
//md5_SystemWideSaltSource(); 使用MD5再加全局加密盐加密的方式加密 -
} -
-
-
publicstatic void md5() { -
newMd5PasswordEncoder md5 = Md5PasswordEncoder(); -
//false 表示:生成32位的Hex版, 这也是encodeHashAsBase64的, Acegi 默认配置; true 表示:生成24位的Base64版 -
false);md5.setEncodeHashAsBase64( -
"123",String pwd = md5.encodePassword( null); -
"MD5:System.out.println( " + "pwd + len=" + pwd.length()); -
} -
-
-
publicstatic void sha_256() { -
newShaPasswordEncoder sha = ShaPasswordEncoder( 256); -
false);sha.setEncodeHashAsBase64( -
"123",String pwd = sha.encodePassword( null); -
"哈希算法System.out.println( 256: " + "pwd + len=" + pwd.length()); -
} -
-
-
publicstatic void sha_SHA_256() { -
newShaPasswordEncoder sha = ShaPasswordEncoder(); -
false);sha.setEncodeHashAsBase64( -
"123",String pwd = sha.encodePassword( null); -
"哈希算法System.out.println( SHA-256: " + "pwd + len=" + pwd.length()); -
} -
-
-
publicstatic void md5_SystemWideSaltSource () { -
newMd5PasswordEncoder md5 = Md5PasswordEncoder(); -
false);md5.setEncodeHashAsBase64( -
-
//使用动态加密盐的只需要在注册用户的时候将第二个参数换成用户名即可 -
"123",String pwd = md5.encodePassword( "acegisalt"); -
"MD5System.out.println( SystemWideSaltSource: " + "pwd + len=" + pwd.length()); -
} - }

基于S3C2440嵌入式Lin
Linux编写Shell脚本之
Linux编写shell脚本之
Android NDK 开发简单
Hello World - Linux
Android 使用【AIDL】
图解 Android Handler
Linux 下 Qt 4.6.0 嵌