spring security中有多种密码加密方式,MD5算法的Md5PasswordEncoder、SHA 算法的ShaPasswordEncoder,但由于是弱加密算法,都被弃用了。推荐使用的是BCrypt算法的BCryptPasswordEncoder。
一、BCryptPasswordEncoder的使用
(一)添加依赖
在SpringBoot项目中加入spring security依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
(二)放行请求
添加了spring security依赖后,所有的请求都被spring security所控制了,这里只是使用BCrypt密码加密的部分,所以需要编写配置类,配置为所有地址都可以匿名访问。
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config