Class Pbkdf2PasswordEncoder
java.lang.Object
org.springframework.security.crypto.password.AbstractValidatingPasswordEncoder
org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
- All Implemented Interfaces:
PasswordEncoder
A
PasswordEncoder implementation that uses PBKDF2 with :
- a configurable random salt value length (default is 16 bytes)
- a configurable number of iterations (default is 310000)
- a configurable key derivation function (see
Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm) - a configurable secret appended to the random salt (default is empty)
- Since:
- 4.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe Algorithm used for creating theSecretKeyFactory -
Constructor Summary
ConstructorsConstructorDescriptionPbkdf2PasswordEncoder(CharSequence secret, int saltLength, int iterations, int hashWidth) Deprecated.Pbkdf2PasswordEncoder(CharSequence secret, int saltLength, int iterations, Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm secretKeyFactoryAlgorithm) Constructs a PBKDF2 password encoder with a secret value as well as salt length, iterations and algorithm. -
Method Summary
Modifier and TypeMethodDescriptionstatic Pbkdf2PasswordEncoderDeprecated.UsedefaultsForSpringSecurity_v5_8()insteadstatic Pbkdf2PasswordEncoderConstructs a PBKDF2 password encoder with no additional secret value.protected StringencodeNonNullPassword(String rawPassword) protected booleanmatchesNonNull(String rawPassword, String encodedPassword) voidsetAlgorithm(Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm secretKeyFactoryAlgorithm) Sets the algorithm to use.voidsetEncodeHashAsBase64(boolean encodeHashAsBase64) Sets if the resulting hash should be encoded as Base64.Methods inherited from class org.springframework.security.crypto.password.AbstractValidatingPasswordEncoder
encode, matches, upgradeEncoding, upgradeEncodingNonNull
-
Constructor Details
-
Pbkdf2PasswordEncoder
@Deprecated public Pbkdf2PasswordEncoder(CharSequence secret, int saltLength, int iterations, int hashWidth) Deprecated.Constructs a PBKDF2 password encoder with a secret value as well as salt length, iterations and hash width.- Parameters:
secret- the secretsaltLength- the salt length (in bytes)iterations- the number of iterations. Users should aim for taking about .5 seconds on their own system.hashWidth- the size of the hash (in bits)- Since:
- 5.5
-
Pbkdf2PasswordEncoder
public Pbkdf2PasswordEncoder(CharSequence secret, int saltLength, int iterations, Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm secretKeyFactoryAlgorithm) Constructs a PBKDF2 password encoder with a secret value as well as salt length, iterations and algorithm.- Parameters:
secret- the secretsaltLength- the salt length (in bytes)iterations- the number of iterations. Users should aim for taking about .5 seconds on their own system.secretKeyFactoryAlgorithm- the algorithm to use- Since:
- 5.8
-
-
Method Details
-
defaultsForSpringSecurity_v5_5
Deprecated.UsedefaultsForSpringSecurity_v5_8()insteadConstructs a PBKDF2 password encoder with no additional secret value. There will be a salt length of 8 bytes, 185,000 iterations, SHA-1 algorithm and a hash length of 256 bits. The default is based upon aiming for .5 seconds to validate the password when this class was added. Users should tune password verification to their own systems.- Returns:
- the
Pbkdf2PasswordEncoder - Since:
- 5.8
-
defaultsForSpringSecurity_v5_8
Constructs a PBKDF2 password encoder with no additional secret value. There will be a salt length of 16 bytes, 310,000 iterations, SHA-256 algorithm and a hash length of 256 bits. The default is based upon aiming for .5 seconds to validate the password when this class was added. Users should tune password verification to their own systems.- Returns:
- the
Pbkdf2PasswordEncoder - Since:
- 5.8
-
setAlgorithm
Sets the algorithm to use. See SecretKeyFactory Algorithms- Parameters:
secretKeyFactoryAlgorithm- the algorithm to use (i.e.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA1,SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256,SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA512)- Since:
- 5.0
-
setEncodeHashAsBase64
public void setEncodeHashAsBase64(boolean encodeHashAsBase64) Sets if the resulting hash should be encoded as Base64. The default is false which means it will be encoded in Hex.- Parameters:
encodeHashAsBase64- true if encode as Base64, false if should use Hex (default)
-
encodeNonNullPassword
- Specified by:
encodeNonNullPasswordin classAbstractValidatingPasswordEncoder
-
matchesNonNull
- Specified by:
matchesNonNullin classAbstractValidatingPasswordEncoder
-
Pbkdf2PasswordEncoder(CharSequence, int, int, SecretKeyFactoryAlgorithm)instead