我正在使用Spring Roo和gvNIX典型的安全性(Spring安全性)。这很棒!谢谢制作人!
使用典型安全性为密码哈希添加salt的最佳方法是什么?
答案 0 :(得分:2)
尝试使用org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
作为建议Spring Security documentation:
始终使用单向密码哈希算法,例如bcrypt,它使用内置的salt值,该值对于每个存储的密码都不同
为此,请按照以下步骤操作:
修改applicationContext-security.xml
文件以更改messageDigestPasswordEncoder
定义,如下所示:
<beans:bean
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"
id="messageDigestPasswordEncoder"/>
修改MessageDigestPasswordEncoder
BCryptPasswordEncoder
的所有引用
用BCryptPasswordEncoder.matches
方法替换任何字符串比较密码验证。 UserController.create
中的示例:
// Replace
//
// if(!savedUser.getPassword().equals(user.getPassword())){
//
// by
if(!messageDigestPasswordEncoder.matches(
user.getPassword(), savedUser.getPassword())){
使用messageDigestPasswordEncoder.encode
在DB上存储密码。
这未经过测试但应该有效。
祝你好运!答案 1 :(得分:0)
你是英雄!
一个小小的补充
<beans:bean class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"
id="bCryptPasswordEncoder">
<beans:constructor-arg name="strength" value="11" />
</beans:bean>
而不是原来的
<beans:constructor-arg value="sha-256"/>
将此标准添加到Typical Security插件是不是一个想法?