Class AbstractPasswordHashCreatorPBKDF2
- java.lang.Object
-
- com.helger.security.password.hash.AbstractPasswordHashCreator
-
- com.helger.security.password.hash.AbstractPasswordHashCreatorPBKDF2
-
- All Implemented Interfaces:
IPasswordHashCreator
- Direct Known Subclasses:
PasswordHashCreatorPBKDF2_SHA256_1000_48
public abstract class AbstractPasswordHashCreatorPBKDF2 extends AbstractPasswordHashCreator
Base class forIPasswordHashCreatorusing the PBKDF2 algorithm.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description protected intm_nHashBytesprotected intm_nIterationsprotected Stringm_sPBKDF2AlgorithmName
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractPasswordHashCreatorPBKDF2(String sAlgorithmName, String sPBKDF2AlgorithmName, int nIterations, int nBytes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringcreatePasswordHash(IPasswordSalt aSalt, String sPlainTextPassword)The method to create a message digest hash from a password.protected static byte[]pbkdf2(char[] aPassword, byte[] aSalt, int nIterations, int nBytes, String sPBKDF2AlgorithmName)Computes the PBKDF2 hash of a password.booleanrequiresSalt()-
Methods inherited from class com.helger.security.password.hash.AbstractPasswordHashCreator
getAlgorithmName, toString
-
-
-
-
Field Detail
-
m_sPBKDF2AlgorithmName
protected final String m_sPBKDF2AlgorithmName
-
m_nIterations
protected final int m_nIterations
-
m_nHashBytes
protected final int m_nHashBytes
-
-
Constructor Detail
-
AbstractPasswordHashCreatorPBKDF2
protected AbstractPasswordHashCreatorPBKDF2(@Nonnull @Nonempty String sAlgorithmName, @Nonnull @Nonempty String sPBKDF2AlgorithmName, @Nonnegative int nIterations, @Nonnegative int nBytes)
-
-
Method Detail
-
requiresSalt
public final boolean requiresSalt()
- Returns:
trueif this hash creator requires a salt,falseif not.
-
pbkdf2
@Nonnull protected static final byte[] pbkdf2(@Nonnull char[] aPassword, @Nonnull byte[] aSalt, @Nonnegative int nIterations, @Nonnegative int nBytes, @Nonnull @Nonempty String sPBKDF2AlgorithmName)
Computes the PBKDF2 hash of a password.- Parameters:
aPassword- the password to hash.aSalt- the saltnIterations- the iteration count (slowness factor)nBytes- the length of the hash to compute in bytessPBKDF2AlgorithmName- The SecretKeyFactory parameter to use. May neither benullnor empty.- Returns:
- the PBDKF2 hash of the password
-
createPasswordHash
@Nonnull public String createPasswordHash(@Nonnull IPasswordSalt aSalt, @Nonnull String sPlainTextPassword)
Description copied from interface:IPasswordHashCreatorThe method to create a message digest hash from a password.- Parameters:
aSalt- Optional salt to be used. This parameter is onlynullfor backwards compatibility reasons.sPlainTextPassword- Plain text password. May not benull.- Returns:
- The String representation of the password hash. Must be valid to encode in UTF-8.
-
-