public class PBKDF2WithHmacSHA extends Object implements PasswordHasher
PBKDF2WithHmacSHA224 PBKDF2WithHmacSHA256 PBKDF2WithHmacSHA384 PBKDF2WithHmacSHA512 -- default
The encoded format produced is as follows:
Where:<algorithm>:<iterations>:<base64(salt)>:<base64(hash)>
Because the algorithm and the parameters used to generate the hash are stored with the hash,
the built-in PBKDF2WithHmacSHA implementation can verify hashes generated using algorithm
and parameter values that differ from the currently configured values. This means the configuration
parameters can be changed without impacting the ability to verify existing password hashes.
(Password hashes generated using algorithms/parameters outside the range supported by
PBKDF2WithHmacSHA cannot be verified.)
| Constructor and Description |
|---|
PBKDF2WithHmacSHA()
Creates a new instance using PBKDF2WithHmacSHA512.
|
PBKDF2WithHmacSHA(String algorithm)
Creates a new instance wit the given algorithm and 2048 iterations and 32 for salt and 64 key size.
|
PBKDF2WithHmacSHA(String algorithm,
int iterations,
int saltSizeBytes,
int keySizeBytes,
SecureRandom random)
Creates a new instance of
PBKDF2WithHmacSHA it also adjust the constructor
parameters if the min values aren't honored. |
| Modifier and Type | Method and Description |
|---|---|
String |
encode(char[] password)
Hashes the given password using PBKDF2.
|
String |
encode(CharSequence rawPassword)
Encode the raw password using a hash algorithm and salt.
|
boolean |
matches(char[] password,
String hashedPassword)
Check the given password against the given hash.
|
boolean |
matches(CharSequence rawPassword,
String encodedPassword)
Verify the encoded password the raw password after.
|
String |
toString() |
public PBKDF2WithHmacSHA(String algorithm, int iterations, int saltSizeBytes, int keySizeBytes, SecureRandom random)
PBKDF2WithHmacSHA it also adjust the constructor
parameters if the min values aren't honored.
Algorithms:
"PBKDF2WithHmacSHA224", "PBKDF2WithHmacSHA256", "PBKDF2WithHmacSHA384", "PBKDF2WithHmacSHA512"
algorithm - default PBKDF2WithHmacSHA512iterations - basically the strength, default 2048saltSizeBytes - default 32keySizeBytes - default 64random - SecureRandom to generate the saltpublic PBKDF2WithHmacSHA()
public PBKDF2WithHmacSHA(String algorithm)
algorithm - e.g. PBKDF2WithHmacSHA512 | PBKDF2WithHmacSHA384 | PBKDF2WithHmacSHA256public String encode(CharSequence rawPassword)
encode in interface PasswordHasherrawPassword - the raw password to encodepublic String encode(char[] password)
password - the password to encode, not nullnullencode(CharSequence)public 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.public boolean matches(char[] password,
String hashedPassword)
password - the entered passwordhashedPassword - the stored password hash to comparetrue if matches, otherwise falsematches(CharSequence, String)Copyright © 2020. All rights reserved.