Spring提供的几种加密类

本文深入探讨了Spring Security下几种常见的加密算法配置,包括PlaintextPasswordEncoder、MD4PasswordEncoder、MD5PasswordEncoder、ShaPasswordEncoder的使用方法及特性,以及如何在配置中正确应用这些算法以确保用户密码的安全。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

执行认证操作公共接口: 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>
 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值