Package com.exedio.cope.pattern
Class MessageDigestAlgorithm
- java.lang.Object
-
- com.exedio.cope.pattern.MessageDigestAlgorithm
-
- All Implemented Interfaces:
Hash.Algorithm
public final class MessageDigestAlgorithm extends Object implements Hash.Algorithm
Uses hash algorithms fromMessageDigest
.- Author:
- Ralf Wiebicke
-
-
Constructor Summary
Constructors Constructor Description MessageDigestAlgorithm(String digest, int saltLength, int iterations)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
check(byte[] plainText, byte[] hash)
Returns whether the given plain text matches the given hash.boolean
compatibleTo(Hash.Algorithm other)
Returns whether this algorithm can consistently check hash values created by the given algorithm.int
getIterations()
int
getSaltLength()
byte[]
hash(byte[] plainText)
Returns a hash for the given plain text.int
length()
String
name()
MessageDigestAlgorithm
salt(int length, SecureRandom source)
-
-
-
Constructor Detail
-
MessageDigestAlgorithm
public MessageDigestAlgorithm(String digest, int saltLength, int iterations)
- Parameters:
digest
- an algorithm name suitable forMessageDigest.getInstance(String)
.
-
-
Method Detail
-
salt
public MessageDigestAlgorithm salt(int length, SecureRandom source)
-
name
public String name()
- Specified by:
name
in interfaceHash.Algorithm
-
length
public int length()
- Specified by:
length
in interfaceHash.Algorithm
-
hash
public byte[] hash(byte[] plainText)
Description copied from interface:Hash.Algorithm
Returns a hash for the given plain text. The result is not required to be deterministic - this means, multiple calls for the same plain text do not have to return the same hash. This is especially true for salted hashes.- Specified by:
hash
in interfaceHash.Algorithm
- Parameters:
plainText
- the text to be hashed. Is never null.- Returns:
- the hash of plainText. Must never return null.
-
check
public boolean check(byte[] plainText, byte[] hash)
Description copied from interface:Hash.Algorithm
Returns whether the given plain text matches the given hash.- Specified by:
check
in interfaceHash.Algorithm
- Parameters:
plainText
- the text to be hashed. Is never null.hash
- the hash of plainText. Is never null.
-
compatibleTo
public boolean compatibleTo(Hash.Algorithm other)
Description copied from interface:Hash.Algorithm
Returns whether this algorithm can consistently check hash values created by the given algorithm.- Specified by:
compatibleTo
in interfaceHash.Algorithm
-
getSaltLength
public int getSaltLength()
-
getIterations
public int getIterations()
-
-