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
APassword
implementation forScramDigestPassword
.- Author:
- Stefan Guilhen
-
-
Field Summary
Fields Modifier and Type Field Description private String
algorithm
private byte[]
digest
private static String
HMAC_SHA1_ALGORITHM
private static String
HMAC_SHA256_ALGORITHM
private static String
HMAC_SHA384_ALGORITHM
private static String
HMAC_SHA512_ALGORITHM
private int
iterationCount
private byte[]
salt
private static long
serialVersionUID
-
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 void
addIterations(byte[] hi, Mac hmac, int currentIterationCount, int newIterationCount)
ScramDigestPasswordImpl
clone()
Creates and returns a copy of thisPassword
.(package private) <T extends KeySpec>
booleanconvertibleTo(Class<T> keySpecType)
boolean
equals(Object obj)
String
getAlgorithm()
byte[]
getDigest()
Get the digest represented by this password.int
getIterationCount()
Get the iteration count used to generate the digest.(package private) <S extends KeySpec>
SgetKeySpec(Class<S> keySpecType)
private static Mac
getMacInstance(String algorithm, byte[] password)
Builds aMac
instance using the specified algorithm and password.byte[]
getSalt()
Get the salt used to generate the digest.int
hashCode()
private static byte[]
hmacPad(String algorithm, byte[] password)
private void
readObject(ObjectInputStream ignored)
(package private) static byte[]
scramDigest(String algorithm, byte[] password, byte[] salt, int iterationCount)
This method implements the SCRAMHi
function as specified by RFC 5802.(package private) static byte[]
scramDigest(String algorithm, byte[] password, byte[] salt, int iterationCount, Charset hashCharset)
(package private) Password
translate(AlgorithmParameterSpec parameterSpec)
(package private) boolean
verify(char[] guess)
(package private) boolean
verify(char[] guess, Charset hashCharset)
(package private) Object
writeReplace()
-
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:
getAlgorithm
in interfaceKey
-
getDigest
public byte[] getDigest()
Description copied from interface:ScramDigestPassword
Get the digest represented by this password.- Specified by:
getDigest
in interfaceScramDigestPassword
- Returns:
- the digest represented by this password
-
getSalt
public byte[] getSalt()
Description copied from interface:ScramDigestPassword
Get the salt used to generate the digest.- Specified by:
getSalt
in interfaceScramDigestPassword
- Returns:
- the salt used to generate the digest
-
getIterationCount
public int getIterationCount()
Description copied from interface:ScramDigestPassword
Get the iteration count used to generate the digest.- Specified by:
getIterationCount
in interfaceScramDigestPassword
- Returns:
- the iteration count used to generate the digest
-
convertibleTo
<T extends KeySpec> boolean convertibleTo(Class<T> keySpecType)
- Specified by:
convertibleTo
in classAbstractPasswordImpl
-
translate
Password translate(AlgorithmParameterSpec parameterSpec) throws InvalidKeyException, InvalidAlgorithmParameterException
- Overrides:
translate
in classAbstractPasswordImpl
- Throws:
InvalidKeyException
InvalidAlgorithmParameterException
-
verify
boolean verify(char[] guess) throws InvalidKeyException
- Specified by:
verify
in classAbstractPasswordImpl
- Throws:
InvalidKeyException
-
verify
boolean verify(char[] guess, Charset hashCharset) throws InvalidKeyException
- Overrides:
verify
in classAbstractPasswordImpl
- Throws:
InvalidKeyException
-
getKeySpec
<S extends KeySpec> S getKeySpec(Class<S> keySpecType) throws InvalidKeySpecException
- Specified by:
getKeySpec
in classAbstractPasswordImpl
- Throws:
InvalidKeySpecException
-
scramDigest
static byte[] scramDigest(String algorithm, byte[] password, byte[] salt, int iterationCount) throws NoSuchAlgorithmException, InvalidKeyException
This method implements the SCRAM
Hi
function 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 Hi
wherei
is 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:
NoSuchAlgorithmException
InvalidKeyException
-
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
Mac
instance 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
Mac
instance. - Throws:
NoSuchAlgorithmException
InvalidKeyException
-
hmacPad
private static byte[] hmacPad(String algorithm, byte[] password) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classAbstractPasswordImpl
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in classAbstractPasswordImpl
-
readObject
private void readObject(ObjectInputStream ignored) throws NotSerializableException
- Throws:
NotSerializableException
-
writeReplace
Object writeReplace()
-
clone
public ScramDigestPasswordImpl clone()
Description copied from interface:Password
Creates and returns a copy of thisPassword
.- Specified by:
clone
in interfaceOneWayPassword
- Specified by:
clone
in interfacePassword
- Specified by:
clone
in interfaceScramDigestPassword
- Specified by:
clone
in classAbstractPasswordImpl
- Returns:
- a copy of this
Password
.
-
-