public class PBKDF2WithHmacSHA1SaltedPasswordEncoder extends java.lang.Object implements PasswordEncoder
<iterations as int> ':' <salt as hex> ':' <hash as hex>.
It can be made stronger by adjusting the number of iterations (see setIterations(int)) as well as the key
length (see setKeyLength(int)).| Modifier and Type | Class and Description |
|---|---|
protected static class |
PBKDF2WithHmacSHA1SaltedPasswordEncoder.EncodedHash |
| Constructor and Description |
|---|
PBKDF2WithHmacSHA1SaltedPasswordEncoder() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected byte[] |
calculateHash(java.lang.String password,
byte[] salt,
int iterations,
int keyLength) |
boolean |
check(java.lang.String uid,
java.lang.String encoded,
java.lang.String plain)
Checks if the
encoded password (from the user, from the database) and the plain password
(from the login screen) matches. |
java.lang.String |
decode(java.lang.String encoded)
Decode the given
encoded password. |
java.lang.String |
encode(java.lang.String uid,
java.lang.String password)
Returns the encoded password string based on the implementation of this interface and by the given
plain password. |
void |
setIterations(int iterations) |
void |
setKeyAlgorithm(java.lang.String keyAlgorithm) |
void |
setKeyLength(int keyLength) |
void |
setSaltAlgorithm(java.lang.String saltAlgorithm) |
void |
setSaltLength(int saltLength) |
public PBKDF2WithHmacSHA1SaltedPasswordEncoder()
public void afterPropertiesSet()
throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmExceptionpublic java.lang.String encode(java.lang.String uid,
java.lang.String password)
PasswordEncoderplain password. The uid can be used as additional salt (see SaltedMD5PasswordEncoder).encode in interface PasswordEncoderuid - mostly userID, mostly not usedpassword - the plain passwordSaltedMD5PasswordEncoder,
PlainTextPasswordEncoderpublic boolean check(java.lang.String uid,
java.lang.String encoded,
java.lang.String plain)
PasswordEncoderencoded password (from the user, from the database) and the plain password
(from the login screen) matches.check in interface PasswordEncoderuid - mostly the user ID and mostly not used. For MD5 used as salt.encoded - the encoded passwordplain - the plain text passwordtrue if they match, false otherwise.MD5PasswordEncoderpublic java.lang.String decode(java.lang.String encoded)
throws EJBCannotDecodePasswordException
PasswordEncoderencoded password. Throws exception if this is not possible.decode in interface PasswordEncoderencoded - the encoded passwordEJBCannotDecodePasswordException - if the password cannot be decoded. (MD5 passwords cannot be decoded)MD5PasswordEncoderprotected byte[] calculateHash(java.lang.String password,
byte[] salt,
int iterations,
int keyLength)
public void setIterations(int iterations)
public void setKeyLength(int keyLength)
public void setKeyAlgorithm(java.lang.String keyAlgorithm)
public void setSaltAlgorithm(java.lang.String saltAlgorithm)
public void setSaltLength(int saltLength)
Copyright © 2018 SAP SE. All Rights Reserved.