Class PBKDF2WithHmacSHA1SaltedPasswordEncoder
- java.lang.Object
-
- de.hybris.platform.persistence.security.PBKDF2WithHmacSHA1SaltedPasswordEncoder
-
- All Implemented Interfaces:
PasswordEncoder,java.io.Serializable,org.springframework.beans.factory.InitializingBean
public class PBKDF2WithHmacSHA1SaltedPasswordEncoder extends java.lang.Object implements PasswordEncoder, org.springframework.beans.factory.InitializingBean
Password encoder using the PBKDF2WithHmacSHA1 algorithm.Note that this encoder is generating a random salt (does not use the user id)! In order to be able to check the salt is stored as part of the encoded hash string.
The encoded format is this:
<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 (seesetKeyLength(int)).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classPBKDF2WithHmacSHA1SaltedPasswordEncoder.EncodedHash
-
Constructor Summary
Constructors Constructor Description PBKDF2WithHmacSHA1SaltedPasswordEncoder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()protected byte[]calculateHash(java.lang.String password, byte[] salt, int iterations, int keyLength)booleancheck(java.lang.String uid, java.lang.String encoded, java.lang.String plain)Checks if theencodedpassword (from the user, from the database) and theplainpassword (from the login screen) matches.java.lang.Stringdecode(java.lang.String encoded)Decode the givenencodedpassword.java.lang.Stringencode(java.lang.String uid, java.lang.String password)Returns the encoded password string based on the implementation of this interface and by the givenplainpassword.voidsetIterations(int iterations)voidsetKeyAlgorithm(java.lang.String keyAlgorithm)voidsetKeyLength(int keyLength)voidsetSaltAlgorithm(java.lang.String saltAlgorithm)voidsetSaltLength(int saltLength)
-
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws java.security.NoSuchAlgorithmException- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.security.NoSuchAlgorithmException
-
encode
public java.lang.String encode(java.lang.String uid, java.lang.String password)Description copied from interface:PasswordEncoderReturns the encoded password string based on the implementation of this interface and by the givenplainpassword. The uid can be used as additional salt (see SaltedMD5PasswordEncoder).- Specified by:
encodein interfacePasswordEncoder- Parameters:
uid- mostly userID, mostly not usedpassword- the plain password- Returns:
- the encoded password
- See Also:
SaltedMD5PasswordEncoder,PlainTextPasswordEncoder
-
check
public boolean check(java.lang.String uid, java.lang.String encoded, java.lang.String plain)Description copied from interface:PasswordEncoderChecks if theencodedpassword (from the user, from the database) and theplainpassword (from the login screen) matches.- Specified by:
checkin interfacePasswordEncoder- Parameters:
uid- mostly the user ID and mostly not used. For MD5 used as salt.encoded- the encoded passwordplain- the plain text password- Returns:
trueif they match,falseotherwise.- See Also:
MD5PasswordEncoder
-
decode
public java.lang.String decode(java.lang.String encoded) throws EJBCannotDecodePasswordExceptionDescription copied from interface:PasswordEncoderDecode the givenencodedpassword. Throws exception if this is not possible.- Specified by:
decodein interfacePasswordEncoder- Parameters:
encoded- the encoded password- Returns:
- the decoded password
- Throws:
EJBCannotDecodePasswordException- if the password cannot be decoded. (MD5 passwords cannot be decoded)- See Also:
MD5PasswordEncoder
-
calculateHash
protected byte[] calculateHash(java.lang.String password, byte[] salt, int iterations, int keyLength)
-
setIterations
public void setIterations(int iterations)
-
setKeyLength
public void setKeyLength(int keyLength)
-
setKeyAlgorithm
public void setKeyAlgorithm(java.lang.String keyAlgorithm)
-
setSaltAlgorithm
public void setSaltAlgorithm(java.lang.String saltAlgorithm)
-
setSaltLength
public void setSaltLength(int saltLength)
-
-