MD5 加密-解密

MD5 加密-解密

别再用简单版MD5加密了,大佬们都这么是使用——>MD5盐值加密多方法详解 - 掘金

使用spring提供的工具 BCryptPasswordEncoder

导入以下依赖


<dependency><groupId>org.springframework.bootgroupId><artifactId>spring-boot-starter-securityartifact><version>2.1.6.RELEASEversion>
dependency>
    @Testvoid contextLoads() throws FileNotFoundException {//new一个 BCryptPasswordEncoderBCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();//调用encode方法进行加密,传入我们需要加密的数据String encode1 = passwordEncoder.encode("123456");String encode2 = passwordEncoder.encode("123456");System.out.println(encode1);System.out.println(encode2);}

使用matches方法进行校验

@Testvoid contextLoads() throws FileNotFoundException {BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();/*** $2a$10$dGhEGYydqI9sOGdslizdmuUKliBsyHdVhON0WVppVRoa5wRHe2SEO* $2a$10$h2PlE5DbDfiClGDw2jGJm.Dp9zNVqOHPADwScJQCDbvG/lzeKOxO6*/boolean test1 = passwordEncoder.matches("123456", "$2a$10$dGhEGYydqI9sOGdslizdmuUKliBsyHdVhON0WVppVRoa5wRHe2SEO");boolean test2 = passwordEncoder.matches("123456", "$2a$10$h2PlE5DbDfiClGDw2jGJm.Dp9zNVqOHPADwScJQCDbvG/lzeKOxO6");System.out.println(test1);System.out.println(test2);}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部