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 TypeMethodDescriptionbooleancheck(byte[] plainText, byte[] hash) Returns whether the given plain text matches the given hash.booleancompatibleTo(Hash.Algorithm other) Returns whether this algorithm can consistently check hash values created by the given algorithm.intintbyte[]hash(byte[] plainText) Returns a hash for the given plain text.intlength()name()salt(int length, SecureRandom source)
-
Constructor Details
-
MessageDigestAlgorithm
- Parameters:
digest- an algorithm name suitable forMessageDigest.getInstance(String).
-
-
Method Details
-
salt
-
name
- Specified by:
namein interfaceHash.Algorithm
-
length
public int length()- Specified by:
lengthin interfaceHash.Algorithm
-
hash
public byte[] hash(byte[] plainText) Description copied from interface:Hash.AlgorithmReturns 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:
hashin 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.AlgorithmReturns whether the given plain text matches the given hash.- Specified by:
checkin 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.AlgorithmReturns whether this algorithm can consistently check hash values created by the given algorithm.- Specified by:
compatibleToin interfaceHash.Algorithm
-
getSaltLength
public int getSaltLength() -
getIterations
public int getIterations()
-