为何每次不同的 密码盐值 却可以校验成功的 关键
public static void main(String[] args) {
String hashpw = BCrypt.hashpw("123", BCrypt.gensalt());
System.out.println(hashpw);
System.out.println(BCrypt.checkpw("123", "$2a$10$4uRhi/76ixeg7KS4p5tf7O3wGKNj1E1.JzbTPpVqrWtwtPHQba.w2"));
}
1.hashpw的 第二个参数 首先要符合 盐值的算法。
2.剖析 hashpw 这个方法
public static String hashpw(String password, String salt) throws IllegalArgumentException {
BCrypt B;
String real_salt;
byte passwordb[], saltb[], hashed[];
char minor = (char) 0;
int rounds, off = 0;
StringBuilder rs = new StringBuilder();
if (salt == null) {
throw new IllegalArgumentException("salt cannot be null");
}
int saltLength = salt.length();
if (saltLength < 28) {
throw new IllegalArgumentException("Invalid salt");
}
if (salt.charAt(0) != '$' || salt.charAt(1) != '2') {
throw new IllegalArgumentException("Invalid salt version");
}
if (s

本文探讨了Spring Security中密码加密的关键——盐值的使用。通过解析`hashpw`方法,揭示了如何利用盐值进行64位解密和加密,形成假密码。在`checkpw`方法中,盐值`saltb`和加密逻辑确保了即使每次加密后的盐值不同,密码验证仍然能够成功。深入理解相关代码能帮助更好地掌握这一过程。
最低0.47元/天 解锁文章
1068

被折叠的 条评论
为什么被折叠?



