Class UnixSHACryptPasswordImpl
- java.lang.Object
-
- org.wildfly.security.password.impl.AbstractPasswordImpl
-
- org.wildfly.security.password.impl.UnixSHACryptPasswordImpl
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Key
,UnixSHACryptPassword
,OneWayPassword
,Password
final class UnixSHACryptPasswordImpl extends AbstractPasswordImpl implements UnixSHACryptPassword
- Author:
- Juraci Paixão Kröhling, David M. Lloyd
-
-
Field Summary
Fields Modifier and Type Field Description private String
algorithm
private byte[]
hash
private int
iterationCount
private byte[]
salt
private static long
serialVersionUID
-
Fields inherited from interface org.wildfly.security.password.interfaces.UnixSHACryptPassword
ALGORITHM_CRYPT_SHA_256, ALGORITHM_CRYPT_SHA_512, DEFAULT_ITERATION_COUNT, SALT_SIZE
-
-
Constructor Summary
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UnixSHACryptPasswordImpl
clone()
Creates and returns a copy of thisPassword
.(package private) <T extends KeySpec>
booleanconvertibleTo(Class<T> keySpecType)
(package private) static byte[]
doEncode(String algorithm, byte[] password, byte[] salt, int iterationCount)
boolean
equals(Object obj)
String
getAlgorithm()
private static byte[]
getDigestA(String algorithm, byte[] password, byte[] salt)
Calculates the "digest A", derived from the password and salt.private static byte[]
getDigestB(byte[] password, byte[] salt, String algorithm)
Returns the "digest B", derived from the password and saltprivate static byte[]
getDigestC(String algorithm, byte[] digestAC, byte[] sequenceP, byte[] sequenceS, int round)
Calculates the "digest C", derived from the sequenceP, sequenceS, digestAC and the iteration roundprivate static byte[]
getDigestDP(String algorithm, byte[] password)
Calculates the "digest DP", derived from the passwordprivate static byte[]
getDigestDS(String algorithm, byte[] digestA, byte[] salt)
Calculates the "digest DS", derived from the salt and on the "digest A"byte[]
getHash()
The final hash, based on the password, salt and iteration countprivate static int
getInputSize(String algorithm)
int
getIterationCount()
The number of iterations to perform when hashing the password.(package private) <S extends KeySpec>
SgetKeySpec(Class<S> keySpecType)
private static MessageDigest
getMessageDigest(String algorithm)
byte[]
getSalt()
The salt used during the hashing of this password.private static byte[]
getSequenceP(String algorithm, byte[] password)
Calculates the "sequence P", derived from the passwordprivate static byte[]
getSequenceS(String algorithm, byte[] digestA, byte[] salt)
Calculates the "sequence S", based on a given "digest A"int
hashCode()
private void
readObject(ObjectInputStream ignored)
private static byte[]
truncatedClone(byte[] salt)
(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, translate
-
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.UnixSHACryptPassword
getParameterSpec, impliesParameters
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
algorithm
private final String algorithm
-
salt
private final byte[] salt
-
iterationCount
private final int iterationCount
-
hash
private final byte[] hash
-
-
Constructor Detail
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(UnixSHACryptPassword password)
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, byte[] clonedSalt, int iterationCount, byte[] hash)
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, char[] passwordChars, Charset hashCharset) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, IteratedSaltedHashPasswordSpec spec)
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, SaltedHashPasswordSpec spec)
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, ClearPasswordSpec spec) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, IteratedSaltedPasswordAlgorithmSpec parameterSpec, char[] password, Charset hashCharset) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, SaltedPasswordAlgorithmSpec parameterSpec, char[] password, Charset hashCharset) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, IteratedPasswordAlgorithmSpec parameterSpec, char[] password, Charset hashCharset) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
UnixSHACryptPasswordImpl
UnixSHACryptPasswordImpl(String algorithm, byte[] clonedSalt, int adjustedIterationCount, char[] password, Charset hashCharset) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
-
Method Detail
-
truncatedClone
private static byte[] truncatedClone(byte[] salt)
-
getSalt
public byte[] getSalt()
Description copied from interface:UnixSHACryptPassword
The salt used during the hashing of this password. Should have at most 16 bytes.- Specified by:
getSalt
in interfaceUnixSHACryptPassword
- Returns:
- the salt
-
getIterationCount
public int getIterationCount()
Description copied from interface:UnixSHACryptPassword
The number of iterations to perform when hashing the password. Should be bigger than 1,000 and lower than 999,999,999. The default value is 5,000- Specified by:
getIterationCount
in interfaceUnixSHACryptPassword
- Returns:
- the number of iterations to perform
-
getHash
public byte[] getHash()
Description copied from interface:UnixSHACryptPassword
The final hash, based on the password, salt and iteration count- Specified by:
getHash
in interfaceUnixSHACryptPassword
- Returns:
- the hash
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceKey
-
getKeySpec
<S extends KeySpec> S getKeySpec(Class<S> keySpecType) throws InvalidKeySpecException
- Specified by:
getKeySpec
in classAbstractPasswordImpl
- Throws:
InvalidKeySpecException
-
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
-
convertibleTo
<T extends KeySpec> boolean convertibleTo(Class<T> keySpecType)
- Specified by:
convertibleTo
in classAbstractPasswordImpl
-
doEncode
static byte[] doEncode(String algorithm, byte[] password, byte[] salt, int iterationCount) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
getDigestA
private static byte[] getDigestA(String algorithm, byte[] password, byte[] salt) throws NoSuchAlgorithmException
Calculates the "digest A", derived from the password and salt.- Parameters:
password
- the encoded password bytes- Returns:
- the digest A
- Throws:
NoSuchAlgorithmException
-
getSequenceS
private static byte[] getSequenceS(String algorithm, byte[] digestA, byte[] salt) throws NoSuchAlgorithmException
Calculates the "sequence S", based on a given "digest A"- Parameters:
digestA
- the digest A- Returns:
- the sequence S
- Throws:
NoSuchAlgorithmException
-
getDigestDS
private static byte[] getDigestDS(String algorithm, byte[] digestA, byte[] salt) throws NoSuchAlgorithmException
Calculates the "digest DS", derived from the salt and on the "digest A"- Parameters:
digestA
- the digest A- Returns:
- the digest DS
- Throws:
NoSuchAlgorithmException
-
getDigestB
private static byte[] getDigestB(byte[] password, byte[] salt, String algorithm) throws NoSuchAlgorithmException
Returns the "digest B", derived from the password and salt- Parameters:
password
- the encoded password bytes- Returns:
- the digest B
- Throws:
NoSuchAlgorithmException
-
getDigestDP
private static byte[] getDigestDP(String algorithm, byte[] password) throws NoSuchAlgorithmException
Calculates the "digest DP", derived from the password- Parameters:
password
- the encoded password bytes- Returns:
- the digest DP
- Throws:
NoSuchAlgorithmException
-
getSequenceP
private static byte[] getSequenceP(String algorithm, byte[] password) throws NoSuchAlgorithmException
Calculates the "sequence P", derived from the password- Parameters:
password
- the encoded password bytes- Returns:
- the sequence P
- Throws:
NoSuchAlgorithmException
-
getDigestC
private static byte[] getDigestC(String algorithm, byte[] digestAC, byte[] sequenceP, byte[] sequenceS, int round) throws NoSuchAlgorithmException
Calculates the "digest C", derived from the sequenceP, sequenceS, digestAC and the iteration round- Parameters:
digestAC
- the digest A/CsequenceP
- the sequence PsequenceS
- the sequence Sround
- the iteration round- Returns:
- the resulting digest C
- Throws:
NoSuchAlgorithmException
-
getMessageDigest
private static MessageDigest getMessageDigest(String algorithm) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
getInputSize
private static int getInputSize(String algorithm) 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 UnixSHACryptPasswordImpl 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 interfaceUnixSHACryptPassword
- Specified by:
clone
in classAbstractPasswordImpl
- Returns:
- a copy of this
Password
.
-
-