密码加解密常用方式

1.添加依赖
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
2.代码演示:
public class Test {
    public static void main(String[] args) {
        BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();
        String password = bCryptPasswordEncoder.encode("abc1233336");
        String password2 = bCryptPasswordEncoder.encode("abc1233336");
        System.out.println(password);
        System.out.println(password2);
        boolean abc1233336 = bCryptPasswordEncoder.matches("abc1233336", password);

        System.out.println(abc1233336);
    }
}

 

 同个密码,加密2次,得出的密文是不一样的,因为每次加密,都是随机生成一个盐进行加密的,那为密码跟密文怎么校验是否一致?原因是密文有固定的格式,同个密文可以解析出盐来,相对于Md5固定加密,更安全




posted @ 2022-06-20 20:46  yangxiaohui227  阅读(399)  评论(0)    收藏  举报