SpringSecurity的new BCryptPasswordEncoder(11)默认参数好像为-1,这个参数作用是什么,盐不是随机数吗,那应该不是盐吧
你所列举的是BCryptPasswordEncoder的三个构造方法。strength作用于盐的产生中。盐的产生是在下列代码中
```public String encode(CharSequence rawPassword) {
String salt;
if (strength > 0) {
if (random != null) {
salt = BCrypt.gensalt(strength, random);
}
else {
//生成盐
salt = BCrypt.gensalt(strength);
}
}
else {
//生成盐
salt = BCrypt.gensalt();
}
return BCrypt.hashpw(rawPassword.toString(), salt);
}
在BCrypt类中有盐生成的细节。
strength这个参数是盐的一部分。看下面的代码
public static String gensalt(int log_rounds, SecureRandom random) {
if (log_rounds < MIN_LOG_ROUNDS || log_rounds > MAX_LOG_ROUNDS) {
throw new IllegalArgumentException("Bad number of rounds");
}
StringBuilder rs = new StringBuilder();
byte rnd[] = new byte[BCRYPT_SALT_LEN];
random.nextBytes(rnd);
rs.append("$2a$");
if (log_rounds < 10) {
rs.append("0");
}
rs.append(log_rounds);
rs.append("$");
encode_base64(rnd, rnd.length, rs);
return rs.toString();
}
最后的rs就是盐的值:$2a$+log_rounds+$