Package com.exedio.cope.pattern
Class MessageDigestAlgorithm
java.lang.Object
com.exedio.cope.pattern.MessageDigestAlgorithm
- All Implemented Interfaces:
Hash.Algorithm
Uses hash algorithms from
MessageDigest
.- Author:
- Ralf Wiebicke
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
int
byte[]
hash
(byte[] plainText) Returns a hash for the given plain text.int
length()
name()
salt
(int length, SecureRandom source)
-
Constructor Details
-
MessageDigestAlgorithm
- Parameters:
digest
- an algorithm name suitable forMessageDigest.getInstance(String)
.
-
-
Method Details
-
salt
-
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
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()
-