Class ScramDigestPasswordImpl
- java.lang.Object
-
- org.wildfly.security.password.impl.AbstractPasswordImpl
-
- org.wildfly.security.password.impl.ScramDigestPasswordImpl
-
- All Implemented Interfaces:
Serializable,Cloneable,Key,ScramDigestPassword,OneWayPassword,Password
class ScramDigestPasswordImpl extends AbstractPasswordImpl implements ScramDigestPassword
APasswordimplementation forScramDigestPassword.- Author:
- Stefan Guilhen
-
-
Field Summary
Fields Modifier and Type Field Description private Stringalgorithmprivate byte[]digestprivate static StringHMAC_SHA1_ALGORITHMprivate static StringHMAC_SHA256_ALGORITHMprivate static StringHMAC_SHA384_ALGORITHMprivate static StringHMAC_SHA512_ALGORITHMprivate intiterationCountprivate byte[]saltprivate static longserialVersionUID-
Fields inherited from interface org.wildfly.security.password.interfaces.ScramDigestPassword
ALGORITHM_SCRAM_SHA_1, ALGORITHM_SCRAM_SHA_256, ALGORITHM_SCRAM_SHA_384, ALGORITHM_SCRAM_SHA_512, DEFAULT_ITERATION_COUNT, DEFAULT_SALT_SIZE
-
-
Constructor Summary
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static voidaddIterations(byte[] hi, Mac hmac, int currentIterationCount, int newIterationCount)ScramDigestPasswordImplclone()Creates and returns a copy of thisPassword.(package private) <T extends KeySpec>
booleanconvertibleTo(Class<T> keySpecType)booleanequals(Object obj)StringgetAlgorithm()byte[]getDigest()Get the digest represented by this password.intgetIterationCount()Get the iteration count used to generate the digest.(package private) <S extends KeySpec>
SgetKeySpec(Class<S> keySpecType)private static MacgetMacInstance(String algorithm, byte[] password)Builds aMacinstance using the specified algorithm and password.byte[]getSalt()Get the salt used to generate the digest.inthashCode()private static byte[]hmacPad(String algorithm, byte[] password)private voidreadObject(ObjectInputStream ignored)(package private) static byte[]scramDigest(String algorithm, byte[] password, byte[] salt, int iterationCount)This method implements the SCRAMHifunction as specified by RFC 5802.(package private) static byte[]scramDigest(String algorithm, byte[] password, byte[] salt, int iterationCount, Charset hashCharset)(package private) Passwordtranslate(AlgorithmParameterSpec parameterSpec)(package private) booleanverify(char[] guess)(package private) booleanverify(char[] guess, Charset hashCharset)(package private) ObjectwriteReplace()-
Methods inherited from class org.wildfly.security.password.impl.AbstractPasswordImpl
getEncoded, getFormat, getNormalizedPasswordBytes, getNormalizedPasswordBytes
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.security.Key
getEncoded, getFormat
-
Methods inherited from interface org.wildfly.security.password.Password
castAndApply, castAndApply, castAs, castAs
-
Methods inherited from interface org.wildfly.security.password.interfaces.ScramDigestPassword
getParameterSpec, impliesParameters
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
HMAC_SHA1_ALGORITHM
private static final String HMAC_SHA1_ALGORITHM
- See Also:
- Constant Field Values
-
HMAC_SHA256_ALGORITHM
private static final String HMAC_SHA256_ALGORITHM
- See Also:
- Constant Field Values
-
HMAC_SHA384_ALGORITHM
private static final String HMAC_SHA384_ALGORITHM
- See Also:
- Constant Field Values
-
HMAC_SHA512_ALGORITHM
private static final String HMAC_SHA512_ALGORITHM
- See Also:
- Constant Field Values
-
algorithm
private final String algorithm
-
digest
private final byte[] digest
-
salt
private final byte[] salt
-
iterationCount
private final int iterationCount
-
-
Constructor Detail
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, byte[] digest, byte[] salt, int iterationCount)
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(ScramDigestPassword password)
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, IteratedSaltedHashPasswordSpec spec)
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, SaltedHashPasswordSpec spec)
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, ClearPasswordSpec spec) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, char[] password, Charset hashCharset) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, char[] password, IteratedSaltedPasswordAlgorithmSpec spec, Charset hashCharset) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, char[] password, SaltedPasswordAlgorithmSpec spec, Charset hashCharset) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, char[] password, IteratedPasswordAlgorithmSpec spec, Charset hashCharset) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, char[] password, byte[] salt, int iterationCount) throws InvalidKeyException, NoSuchAlgorithmException
-
ScramDigestPasswordImpl
ScramDigestPasswordImpl(String algorithm, char[] password, byte[] salt, int iterationCount, Charset hashCharset) throws InvalidKeyException, NoSuchAlgorithmException
-
-
Method Detail
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithmin interfaceKey
-
getDigest
public byte[] getDigest()
Description copied from interface:ScramDigestPasswordGet the digest represented by this password.- Specified by:
getDigestin interfaceScramDigestPassword- Returns:
- the digest represented by this password
-
getSalt
public byte[] getSalt()
Description copied from interface:ScramDigestPasswordGet the salt used to generate the digest.- Specified by:
getSaltin interfaceScramDigestPassword- Returns:
- the salt used to generate the digest
-
getIterationCount
public int getIterationCount()
Description copied from interface:ScramDigestPasswordGet the iteration count used to generate the digest.- Specified by:
getIterationCountin interfaceScramDigestPassword- Returns:
- the iteration count used to generate the digest
-
convertibleTo
<T extends KeySpec> boolean convertibleTo(Class<T> keySpecType)
- Specified by:
convertibleToin classAbstractPasswordImpl
-
translate
Password translate(AlgorithmParameterSpec parameterSpec) throws InvalidKeyException, InvalidAlgorithmParameterException
- Overrides:
translatein classAbstractPasswordImpl- Throws:
InvalidKeyExceptionInvalidAlgorithmParameterException
-
verify
boolean verify(char[] guess) throws InvalidKeyException- Specified by:
verifyin classAbstractPasswordImpl- Throws:
InvalidKeyException
-
verify
boolean verify(char[] guess, Charset hashCharset) throws InvalidKeyException- Overrides:
verifyin classAbstractPasswordImpl- Throws:
InvalidKeyException
-
getKeySpec
<S extends KeySpec> S getKeySpec(Class<S> keySpecType) throws InvalidKeySpecException
- Specified by:
getKeySpecin classAbstractPasswordImpl- Throws:
InvalidKeySpecException
-
scramDigest
static byte[] scramDigest(String algorithm, byte[] password, byte[] salt, int iterationCount) throws NoSuchAlgorithmException, InvalidKeyException
This method implements the SCRAM
Hifunction as specified by RFC 5802. The function is defined as follows:Hi(str, salt, i) U1 <- HMAC(str, salt + INT(1)) U2 <- HMAC(str, U1) ... Ui-1 <- HMAC(str, Ui-2) Ui <- HMAC(str, Ui-1) Hi <- U1 XOR U2 XOR ... XOR Ui return Hiwhereiis the iteration count,+is the string concatenation operator, andINT(g)is a 4-octet encoding of the integerg, most significant octet first.- Parameters:
algorithm- the algorithm that should be used to hash the password.password- the password to be hashed.salt- the salt used to hash the password.iterationCount- the iteration count used to hash the password.- Returns:
- a byte[] containing the hashed password.
- Throws:
NoSuchAlgorithmExceptionInvalidKeyException
-
scramDigest
static byte[] scramDigest(String algorithm, byte[] password, byte[] salt, int iterationCount, Charset hashCharset) throws NoSuchAlgorithmException, InvalidKeyException
-
addIterations
static void addIterations(byte[] hi, Mac hmac, int currentIterationCount, int newIterationCount)
-
getMacInstance
private static Mac getMacInstance(String algorithm, byte[] password) throws NoSuchAlgorithmException, InvalidKeyException
Builds a
Macinstance using the specified algorithm and password.- Parameters:
algorithm- the algorithm that should be used to hash the password.password- the password to be hashed. It will be padded according to the HMAC block size.- Returns:
- the constructed
Macinstance. - Throws:
NoSuchAlgorithmExceptionInvalidKeyException
-
hmacPad
private static byte[] hmacPad(String algorithm, byte[] password) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
hashCode
public int hashCode()
- Specified by:
hashCodein classAbstractPasswordImpl
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin classAbstractPasswordImpl
-
readObject
private void readObject(ObjectInputStream ignored) throws NotSerializableException
- Throws:
NotSerializableException
-
writeReplace
Object writeReplace()
-
clone
public ScramDigestPasswordImpl clone()
Description copied from interface:PasswordCreates and returns a copy of thisPassword.- Specified by:
clonein interfaceOneWayPassword- Specified by:
clonein interfacePassword- Specified by:
clonein interfaceScramDigestPassword- Specified by:
clonein classAbstractPasswordImpl- Returns:
- a copy of this
Password.
-
-