Spring Data——MD5加密

一、导入依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

二、配置:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/**").permitAll()
                .anyRequest().authenticated()
                .and().csrf().disable();
    }

    @Bean
    public BCryptPasswordEncoder bcryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

三、测试:

@RunWith(SpringRunner.class)
@SpringBootTest
public class MystoreSsoWebApplicationTests {
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Test
    public void contextLoads() {
        System.out.println(bCryptPasswordEncoder.encode("123456"));
        System.out.println(bCryptPasswordEncoder.encode("123456"));
        System.out.println(bCryptPasswordEncoder.encode("123456"));

        System.out.println(bCryptPasswordEncoder.matches("123456", bCryptPasswordEncoder.encode("123456")));
    }
}
$2a$10$66.q2jeVlDuSU0/JwnpEfeEo7v3z9qAYtxTVaSYR9WmXDDd4w5rkO
$2a$10$fgT/cU.oYzrRqAe982qZbeMybPpGO5dNuZ8iTDYlK/K1Bw.T5ALF2
$2a$10$nffu8VRnX7uQWxW.HZNJK.n2syGohbmqDE3S9D7crJw9gCXcGOGtO
true

 

posted @ 2019-08-05 18:40  开拖拉机的拉风少年  阅读(286)  评论(0编辑  收藏  举报