Class 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 Details

    • CHUNK_SIZE

      public static final int CHUNK_SIZE
      Chunk size used in stream-based digestion.
      See Also:
    • digest

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

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

    • 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 Details

    • 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