Class MessageDigester
java.lang.Object
org.deltava.crypt.MessageDigester
A class to generate MD5/SHA message digests.
- Since:
- 1.0
- Version:
- 11.1
- Author:
- Luke
-
Constructor Summary
ConstructorsConstructorDescriptionMessageDigester
(String algorithm) Create a new Message Digester with a specified algorithm.MessageDigester
(String algorithm, int bufSize) Create a new Message Digester with a specified algorithm and input buffer size. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
convert
(byte[] hash) Converts a message digest into a hexadecimal String.byte[]
digest
(byte[] data) Returns the message digest value for a given amount of data.byte[]
digest
(InputStream is) Returns the message digest value for the data within a given stream.final String
Return the Message Digest algorithm in use.static byte[]
Converts a hexadecimal String into a byte array.void
reset()
Resets the Message Digester.void
"Salts" the message digest by processing a string before the actual data.final void
setBufferSize
(int size) Updates the buffer size.
-
Constructor Details
-
MessageDigester
Create a new Message Digester with a specified algorithm.- Parameters:
algorithm
- the algorithm to use; must be supported by the JVM- Throws:
CryptoException
-
MessageDigester
Create a new Message Digester with a specified algorithm and input buffer size.- Parameters:
algorithm
- the algorithm to use; must be supported by the JVMbufSize
- the buffer Size in bytes.- See Also:
-
-
Method Details
-
salt
"Salts" the message digest by processing a string before the actual data. This is used to protect (somewhat) against reverse engineering the hash through brute force.- Parameters:
saltValue
- the salt string- Throws:
NullPointerException
- if saltValue is null
-
getAlgorithm
Return the Message Digest algorithm in use.- Returns:
- the algorithm name
-
setBufferSize
public final void setBufferSize(int size) Updates the buffer size.- Parameters:
size
- the new buffer size in bytes. Must be > 64
-
digest
public byte[] digest(byte[] data) Returns the message digest value for a given amount of data.- Parameters:
data
- the data to digest- Returns:
- the message digest
-
digest
Returns the message digest value for the data within a given stream.- Parameters:
is
- the stream containing the data- Returns:
- the message digest
- Throws:
IOException
- if an error occurs reading the data
-
reset
public void reset()Resets the Message Digester. -
convert
Converts a message digest into a hexadecimal String.- Parameters:
hash
- the message digest- Returns:
- the hexadecimal representation of the message digest
-
parse
Converts a hexadecimal String into a byte array.- Parameters:
hash
- the hexadecimal message digest- Returns:
- the message digest
-