edu.vt.middleware.crypt.digest
Class DigestAlgorithm

java.lang.Object
  extended by edu.vt.middleware.crypt.AbstractAlgorithm
      extended by edu.vt.middleware.crypt.AbstractRandomizableAlgorithm
          extended by 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

public class DigestAlgorithm
extends AbstractRandomizableAlgorithm
implements Cloneable

DigestAlgorithm provides message digest operations.

Version:
$Revision: 2744 $
Author:
Middleware Services

Field Summary
static int CHUNK_SIZE
          Chunk size used in stream-based digestion.
protected  org.bouncycastle.crypto.Digest digest
          Digest instance used for digest computation.
protected  byte[] salt
          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, logger, randomProvider
 
Constructor Summary
protected DigestAlgorithm(org.bouncycastle.crypto.Digest d)
          Creates a new digest algorithm that uses the given Digest for digest computation.
 
Method Summary
 Object clone()
          
 byte[] digest(byte[] input)
          Computes the digest for the given data in a single operation.
 String digest(byte[] input, Converter converter)
          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.
 String 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 getDigest()
          Gets the underlying object that performs digest computation.
 byte[] getRandomSalt()
          Gets a random salt in the amount specified by AbstractRandomizableAlgorithm.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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHUNK_SIZE

public static final int CHUNK_SIZE
Chunk size used in stream-based digestion.

See Also:
Constant Field Values

digest

protected org.bouncycastle.crypto.Digest digest
Digest instance used for digest computation.


salt

protected byte[] salt
Random data used to initialize digest.

Constructor Detail

DigestAlgorithm

protected DigestAlgorithm(org.bouncycastle.crypto.Digest d)
Creates a new digest algorithm that uses the given Digest for digest computation.

Parameters:
d - Used for digest computation.
Method Detail

newInstance

public static DigestAlgorithm newInstance(String algorithm)
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 by AbstractRandomizableAlgorithm.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

public String digest(byte[] input,
                     Converter converter)
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

public byte[] digest(InputStream in)
              throws IOException
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

public String digest(InputStream in,
                     Converter converter)
              throws IOException
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

public Object clone()
             throws CloneNotSupportedException

Overrides:
clone in class Object
Throws:
CloneNotSupportedException


Copyright © 2003-2013 Virginia Tech. All Rights Reserved.