public class BCryptPbkdf2PasswordHash extends Object implements PasswordHasher
PBKDF2WithHmacSHA for Java EE algorithms and BCryptPasswordEncoder
for Spring boot supported security stores.
Support the following hash Algorithm:
The encoded format as follows for *SHA* algorithms:PBKDF2WithHmacSHA224 PBKDF2WithHmacSHA256 PBKDF2WithHmacSHA384 PBKDF2WithHmacSHA512 BCrypt
Where:<algorithm>:<iterations>:<base64(salt)>:<base64(hash)>
<spring boot BCrypt encoded password>
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BCRYPT_STRENGTH
the log rounds to use, between 4 and 31, default is 10
|
static BCryptPasswordEncoder.BCryptVersion |
DEFAULT_VERSION |
| Constructor and Description |
|---|
BCryptPbkdf2PasswordHash()
Creates a new instance using
Algorithm.BCrypt to hash passwords. |
BCryptPbkdf2PasswordHash(Algorithm algorithm)
Creates a new
BCryptPbkdf2PasswordHash using the Algorithm in the default config. |
BCryptPbkdf2PasswordHash(PasswordHasher defaultHasher,
PBKDF2WithHmacSHA pbkdf2WithHmacSHA,
BCryptPasswordEncoder bCryptPasswordEncoder)
Consider using the static factory methods.
|
| Modifier and Type | Method and Description |
|---|---|
String |
encode(CharSequence rawPassword)
Encodes the password using the
Algorithm of the constructor. |
boolean |
matches(CharSequence rawPassword,
String encodedPassword)
Decodes the password based of the prefixed algorithm, using either PBKDF2xx or BCrypt.
|
static BCryptPbkdf2PasswordHash |
newBCryptPasswordEncoder(int strength,
BCryptPasswordEncoder.BCryptVersion version,
SecureRandom random)
Creates a new instance of
BCryptPbkdf2PasswordHash using BCrypt to
hash new passwords. |
static BCryptPbkdf2PasswordHash |
newPBKDF2Encoder(int iterations,
int saltSizeBytes,
int keySizeBytes,
Algorithm algorithm,
SecureRandom random)
Creates a new instance of
BCryptPbkdf2PasswordHash using PBKDF2WithHmacSHA to
hash new passwords. |
String |
toString() |
public static final int DEFAULT_BCRYPT_STRENGTH
public static final BCryptPasswordEncoder.BCryptVersion DEFAULT_VERSION
public BCryptPbkdf2PasswordHash()
Algorithm.BCrypt to hash passwords.public BCryptPbkdf2PasswordHash(Algorithm algorithm)
BCryptPbkdf2PasswordHash using the Algorithm in the default config.algorithm - the Algorithm to use.public BCryptPbkdf2PasswordHash(PasswordHasher defaultHasher, PBKDF2WithHmacSHA pbkdf2WithHmacSHA, BCryptPasswordEncoder bCryptPasswordEncoder)
defaultHasher - the hasher to use if encode(CharSequence) is calledpbkdf2WithHmacSHA - the configured PBKDF2WithHmacSHAbCryptPasswordEncoder - the configured BCryptPasswordEncoderpublic static BCryptPbkdf2PasswordHash newBCryptPasswordEncoder(int strength, BCryptPasswordEncoder.BCryptVersion version, SecureRandom random)
BCryptPbkdf2PasswordHash using BCrypt to
hash new passwords.strength - the log rounds to use, between 4 and 31, default is 10version - (optional) default is BCryptPasswordEncoder.BCryptVersion.$2Arandom - (optional) SecureRandom used to hash new passwordsBCryptPbkdf2PasswordHash, never nullpublic static BCryptPbkdf2PasswordHash newPBKDF2Encoder(int iterations, int saltSizeBytes, int keySizeBytes, Algorithm algorithm, SecureRandom random)
BCryptPbkdf2PasswordHash using PBKDF2WithHmacSHA to
hash new passwords.
Algorithms:
PBKDF2WithHmacSHA224 PBKDF2WithHmacSHA256 PBKDF2WithHmacSHA384 PBKDF2WithHmacSHA512
iterations - basically the strength, default 2048saltSizeBytes - e.g. 32keySizeBytes - e.g. 32algorithm - (optional) default PBKDF2WithHmacSHA512random - (optional) SecureRandom to generate the saltBCryptPbkdf2PasswordHash, never nullpublic String encode(CharSequence rawPassword)
Algorithm of the constructor.
Encode the raw password using a hash algorithm and salt.encode in interface PasswordHasherrawPassword - the raw password to encodepublic boolean matches(CharSequence rawPassword, String encodedPassword)
true if the passwords matches,
false if they do not.matches in interface PasswordHasherrawPassword - the raw password to encode and matchencodedPassword - the encoded password from storage to compare withtrue if the raw password matches the encoded one.Copyright © 2020. All rights reserved.