Class UnixMD5CryptPasswordImpl
- java.lang.Object
-
- org.wildfly.security.password.impl.AbstractPasswordImpl
-
- org.wildfly.security.password.impl.UnixMD5CryptPasswordImpl
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Key
,UnixMD5CryptPassword
,OneWayPassword
,Password
final class UnixMD5CryptPasswordImpl extends AbstractPasswordImpl implements UnixMD5CryptPassword
Implementation of the Unix MD5 Crypt password.- Author:
- Farah Juma, David M. Lloyd
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
hash
(package private) static byte[]
MAGIC_BYTES
(package private) static String
MD5
private byte[]
salt
private static long
serialVersionUID
-
Fields inherited from interface org.wildfly.security.password.interfaces.UnixMD5CryptPassword
ALGORITHM_CRYPT_MD5, ITERATION_COUNT, SALT_SIZE
-
-
Constructor Summary
Constructors Constructor Description UnixMD5CryptPasswordImpl(byte[] clonedHash, byte[] clonedSalt)
UnixMD5CryptPasswordImpl(char[] password, byte[] salt, Charset hashCharset)
UnixMD5CryptPasswordImpl(char[] password, Charset hashCharset)
UnixMD5CryptPasswordImpl(char[] password, SaltedPasswordAlgorithmSpec spec, Charset hashCharset)
UnixMD5CryptPasswordImpl(UnixMD5CryptPassword password)
UnixMD5CryptPasswordImpl(ClearPasswordSpec spec)
UnixMD5CryptPasswordImpl(SaltedHashPasswordSpec spec)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UnixMD5CryptPasswordImpl
clone()
Creates and returns a copy of thisPassword
.(package private) <T extends KeySpec>
booleanconvertibleTo(Class<T> keySpecType)
(package private) static byte[]
encode(byte[] password, byte[] salt)
Hashes the given password using the MD5 Crypt algorithm.boolean
equals(Object obj)
String
getAlgorithm()
byte[]
getHash()
Get the hash component of this password.(package private) <S extends KeySpec>
SgetKeySpec(Class<S> keySpecType)
(package private) static MessageDigest
getMD5MessageDigest()
byte[]
getSalt()
Get the salt component of this password.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.UnixMD5CryptPassword
getParameterSpec, impliesParameters
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
MD5
static final String MD5
- See Also:
- Constant Field Values
-
MAGIC_BYTES
static final byte[] MAGIC_BYTES
-
hash
private final byte[] hash
-
salt
private final byte[] salt
-
-
Constructor Detail
-
UnixMD5CryptPasswordImpl
UnixMD5CryptPasswordImpl(byte[] clonedHash, byte[] clonedSalt)
-
UnixMD5CryptPasswordImpl
UnixMD5CryptPasswordImpl(UnixMD5CryptPassword password)
-
UnixMD5CryptPasswordImpl
UnixMD5CryptPasswordImpl(SaltedHashPasswordSpec spec)
-
UnixMD5CryptPasswordImpl
UnixMD5CryptPasswordImpl(ClearPasswordSpec spec) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
UnixMD5CryptPasswordImpl
UnixMD5CryptPasswordImpl(char[] password, Charset hashCharset) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
UnixMD5CryptPasswordImpl
UnixMD5CryptPasswordImpl(char[] password, SaltedPasswordAlgorithmSpec spec, Charset hashCharset) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
UnixMD5CryptPasswordImpl
UnixMD5CryptPasswordImpl(char[] password, byte[] salt, Charset hashCharset) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
-
Method Detail
-
truncatedClone
private static byte[] truncatedClone(byte[] salt)
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceKey
-
getHash
public byte[] getHash()
Description copied from interface:UnixMD5CryptPassword
Get the hash component of this password.- Specified by:
getHash
in interfaceUnixMD5CryptPassword
- Returns:
- the hash component
-
getSalt
public byte[] getSalt()
Description copied from interface:UnixMD5CryptPassword
Get the salt component of this password.- Specified by:
getSalt
in interfaceUnixMD5CryptPassword
- Returns:
- the salt component
-
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
-
encode
static byte[] encode(byte[] password, byte[] salt) throws NoSuchAlgorithmException
Hashes the given password using the MD5 Crypt algorithm.- Parameters:
password
- the password to be hashedsalt
- the salt, will be truncated to an array of 8 bytes if an array larger than 8 bytes is given- Returns:
- a
byte[]
containing the hashed password - Throws:
NoSuchAlgorithmException
- if aMessageDigest
object that implements MD5 cannot be retrieved
-
getMD5MessageDigest
static MessageDigest getMD5MessageDigest() 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 UnixMD5CryptPasswordImpl 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 interfaceUnixMD5CryptPassword
- Specified by:
clone
in classAbstractPasswordImpl
- Returns:
- a copy of this
Password
.
-
-