执行认证操作公共接口: PasswordEncoder
PlaintextPasswordEncoder: 密码明文实现类
Plaintext implementation of PasswordEncoder.
As callers may wish to extract the password and salts separately from the encoded password, the salt must not contain reserved characters (specifically '{' and '}').
Md4PasswordEncoder:
MD4 implementation of PasswordEncoder.
If a null
password is presented, it will be treated as an empty String
("") password.
As MD4 is a one-way hash, the salt can contain any characters.
Md5PasswordEncoder:
MD5 implementation of PasswordEncoder.
If a null
password is presented, it will be treated as an empty String
("") password.
As MD5 is a one-way hash, the salt can contain any characters.
ShaPasswordEncoder:
SHA implementation of PasswordEncoder.
If a null
password is presented, it will be treated as an empty String
("") password.
As SHA is a one-way hash, the salt can contain any characters. The default strength for the SHA encoding is SHA-1. If you wish to use higher strengths use the argumented constructor。
常有的加密算法说明如下:
1) MD4
MD4(RFC 1320)是 MIT 的 Ronald L. Rivest 在 1990 年设计的,MD 是 Message Digest 的缩写。它适用在32位字长的处理器上用高速软件 实现--它是基于 32 位操作数的位操作来实现的。
2) MD5
MD5(RFC 1321)是 Rivest 于1991年对MD4的改进版本。它对输入仍以512位分组,其输出是4个32位字的级联,与 MD4 相同。MD5比MD4来得复杂,并且速度较之要慢一点,但更安全,在抗分析和抗差分方面表现更好
3) SHA1 及其他
SHA1是由NIST NSA设计为同DSA一起使用的,它对长度小于264的输入,产生长度为160bit的散列值,因此抗穷举(brute-force)性更好。SHA-1 设计时基于和MD4相同原理,并且模仿了该算法。
Spring Security下配置这些加密如下:
<bean id="blPasswordEncoder" class="org.springframework.security.authentication. encoding.PlaintextPasswordEncoder"/> <sec:authentication-manager alias="blAuthenticationManager"> <sec:authentication-provider user-service-ref="blUserDetailsService" > <sec:password-encoder ref="blPasswordEncoder"/> </sec:authentication-provider> </sec:authentication-manager>