Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class Pbkdf2PasswordEncoder
- Object
- Pbkdf2PasswordEncoder
ImplementsPasswordEncoder
Reads the PBKDF2 passwords Spring Security’s Pbkdf2PasswordEncoder wrote,
so a user table brought over from a Spring application signs its users in
as it is.
A stored value is the salt followed by the derived key, as hexadecimal – or base64, where the application had set that. How many rounds, which digest and how long the salt is are not in it: they are whatever the encoder that wrote it was configured with, and this one has to be configured the same.
| Stored as | Written by | Made with |
|---|---|---|
{pbkdf2} | defaultsForSpringSecurity_v5_5 | SHA-1, 185000 rounds, 8 byte salt |
{pbkdf2@SpringSecurity_v5_8} | defaultsForSpringSecurity_v5_8 | SHA-256, 310000 rounds, 16 byte salt |
Both are registered in the encoder PasswordEncoderFactories makes, for
verifying. New passwords get {pbkdf2-sha256}, whose stored form says how
it was made; a sign-in with an older one re-encodes it.
Constructors
public Pbkdf2PasswordEncoder(CharSequence secret, int saltLength, int iterations, String digest) |
Methods
public static Pbkdf2PasswordEncoder defaultsForSpringSecurity_v5_5() | What Spring Security wrote as {pbkdf2} up to its version 5.7, and still reads under that id: SHA-1, 185000 rounds, an 8 byte salt and a 32 byte key. |
public static Pbkdf2PasswordEncoder defaultsForSpringSecurity_v5_8() | What Spring Security writes as {pbkdf2@SpringSecurity_v5_8}: SHA-256, 310000 rounds, a 16 byte salt and a 32 byte key. |
public void setEncodeHashAsBase64(boolean encodeHashAsBase64) | Whether stored values are base64 rather than hexadecimal; hexadecimal unless set. |
public String encode(CharSequence rawPassword) | The password as it should be stored: salted and hashed, so encoding one password twice gives two different results. |
public boolean matches(CharSequence rawPassword, String encodedPassword) | Whether rawPassword is the password encodedPassword was made from. |
Inherited methods
Constructor details
Pbkdf2PasswordEncoder
public Pbkdf2PasswordEncoder(CharSequence secret, int saltLength, int iterations, String digest)Parameters
secretCharSequence- a value mixed into every salt – Spring’s “pepper”; empty for none
saltLengthint- the bytes of salt in front of every stored value
iterationsint- the rounds
digestStringCrypto.SHA1,Crypto.SHA256orCrypto.SHA512
Method details
defaultsForSpringSecurity_v5_5
public static Pbkdf2PasswordEncoder defaultsForSpringSecurity_v5_5(){pbkdf2} up to its version 5.7, and
still reads under that id: SHA-1, 185000 rounds, an 8 byte salt and a 32
byte key.defaultsForSpringSecurity_v5_8
public static Pbkdf2PasswordEncoder defaultsForSpringSecurity_v5_8(){pbkdf2@SpringSecurity_v5_8}: SHA-256,
310000 rounds, a 16 byte salt and a 32 byte key.setEncodeHashAsBase64
public void setEncodeHashAsBase64(boolean encodeHashAsBase64)encode
public String encode(CharSequence rawPassword)matches
public boolean matches(CharSequence rawPassword, String encodedPassword)rawPassword is the password encodedPassword was made from.