java.lang.Object
edu.vt.middleware.crypt.AbstractAlgorithm
edu.vt.middleware.crypt.AbstractRandomizableAlgorithm
edu.vt.middleware.crypt.digest.DigestAlgorithm
- All Implemented Interfaces:
Algorithm
,Randomizable
,Cloneable
- Direct Known Subclasses:
MD2
,MD4
,MD5
,RipeMD128
,RipeMD160
,RipeMD256
,RipeMD320
,SHA1
,SHA256
,SHA384
,SHA512
,Tiger
,Whirlpool
DigestAlgorithm
provides message digest operations.- Version:
- $Revision: 2744 $
- Author:
- Middleware Services
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Chunk size used in stream-based digestion.protected org.bouncycastle.crypto.Digest
Digest instance used for digest computation.protected byte[]
Random data used to initialize digest.Fields inherited from class edu.vt.middleware.crypt.AbstractRandomizableAlgorithm
randomByteSize
Fields inherited from class edu.vt.middleware.crypt.AbstractAlgorithm
algorithm, randomProvider
-
Constructor Summary
ModifierConstructorDescriptionprotected
DigestAlgorithm
(org.bouncycastle.crypto.Digest d) Creates a new digest algorithm that uses the givenDigest
for digest computation. -
Method Summary
Modifier and TypeMethodDescriptionclone()
byte[]
digest
(byte[] input) Computes the digest for the given data in a single operation.Computes the digest for the given data in a single operation and passes the resulting digest bytes through the given converter to produce text output.byte[]
digest
(InputStream in) Computes the digest for all the data in the stream by reading data and hashing it in chunks.digest
(InputStream in, Converter converter) Computes the digest for all the data in the stream by reading data and hashing it in chunks.org.bouncycastle.crypto.Digest
Gets the underlying object that performs digest computation.byte[]
Gets a random salt in the amount specified byAbstractRandomizableAlgorithm.getRandomByteSize()
.static DigestAlgorithm
newInstance
(String algorithm) Creates a new digest algorithm instance from its name, e.g.protected void
setDigest
(org.bouncycastle.crypto.Digest d) Sets the internal object responsible for digest computation.void
setSalt
(byte[] randomBytes) Sets the salt used to randomize the digest prior to digestion.Methods inherited from class edu.vt.middleware.crypt.AbstractRandomizableAlgorithm
getRandomByteSize, setRandomByteSize
Methods inherited from class edu.vt.middleware.crypt.AbstractAlgorithm
getAlgorithm, getRandomData, setRandomProvider, toString
-
Field Details
-
CHUNK_SIZE
public static final int CHUNK_SIZEChunk size used in stream-based digestion.- See Also:
-
digest
protected org.bouncycastle.crypto.Digest digestDigest instance used for digest computation. -
salt
protected byte[] saltRandom data used to initialize digest.
-
-
Constructor Details
-
DigestAlgorithm
protected DigestAlgorithm(org.bouncycastle.crypto.Digest d) Creates a new digest algorithm that uses the givenDigest
for digest computation.- Parameters:
d
- Used for digest computation.
-
-
Method Details
-
newInstance
Creates a new digest algorithm instance from its name, e.g. SHA-1 for a SHA1 digest.- Parameters:
algorithm
- Name of a message digest algorithm.- Returns:
- Digest algorithm instance that provides the requested algorithm.
-
setDigest
protected void setDigest(org.bouncycastle.crypto.Digest d) Sets the internal object responsible for digest computation.- Parameters:
d
- Used for digest computation.
-
setSalt
public void setSalt(byte[] randomBytes) Sets the salt used to randomize the digest prior to digestion.- Parameters:
randomBytes
- Random data to initialize digest.
-
getRandomSalt
public byte[] getRandomSalt()Gets a random salt in the amount specified byAbstractRandomizableAlgorithm.getRandomByteSize()
.- Returns:
- Random salt.
-
getDigest
public org.bouncycastle.crypto.Digest getDigest()Gets the underlying object that performs digest computation.- Returns:
- Digest instance.
-
digest
public byte[] digest(byte[] input) Computes the digest for the given data in a single operation.- Parameters:
input
- Data to be digested.- Returns:
- Message digest as byte array.
-
digest
Computes the digest for the given data in a single operation and passes the resulting digest bytes through the given converter to produce text output.- Parameters:
input
- Data to be digested.converter
- Converts digest bytes to some string representation, e.g Base-64 encoded text.- Returns:
- String representation of digest as provided by the converter.
-
digest
Computes the digest for all the data in the stream by reading data and hashing it in chunks.- Parameters:
in
- Input stream containing data to be digested.- Returns:
- Message digest as byte array.
- Throws:
IOException
- On input stream read errors.
-
digest
Computes the digest for all the data in the stream by reading data and hashing it in chunks. The output is converted to a string representation by the given converter.- Parameters:
in
- Input stream containing data to be digested.converter
- Converts digest bytes to some string representation, e.g Base-64 encoded text.- Returns:
- String representation of digest as provided by the converter.
- Throws:
IOException
- On input stream read errors.
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-