Java开发 BCryptPasswordEncoder加密解密测试
程序员文章站
2022-04-15 23:23:13
生成密码代码:public class BCryptPasswordEncoderDemo { public static void main(String[] args) { BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder(); String password = "123456"; String hashPass = bcryptPasswordEn...
生成密码代码:
public class BCryptPasswordEncoderDemo { public static void main(String[] args) { BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder(); String password = "123456"; String hashPass = bcryptPasswordEncoder.encode(password ); System.out.println(hashPass); } }
对"123456" 进行加密之后结果:
$2a$10$6iIpLfj2D3aBv5FceVPLNe5ZIX0UO9vZRa/mhOSXGrRbFZo3w0vS2
判断明文密文是相同代码:
boolean b = bcryptPasswordEncoder.matches("123456","$2a$10$6iIpLfj2D3aBv5FceVPLNe5ZIX0UO9vZRa/mhOSXGrRbFZo3w0vS2"); System.out.println(b);
如果匹配一致,结果为true
本文地址:https://blog.csdn.net/JavaNovice_Wy/article/details/108238926
上一篇: Java中枚举的定义
下一篇: 基本算法排序