为何每次不同的 密码盐值 却可以校验成功的 关键
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&