Oracle Security Developer Tools Crypto Java API Reference
10g (10.1.4.0.1)

B28171-01


oracle.security.crypto.core
Class MessageDigest

java.lang.Object
  extended byoracle.security.crypto.core.MessageDigest

All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
HMAC, MD2, MD4, MD5, PasswordBasedMAC, SHA

public abstract class MessageDigest
extends java.lang.Object
implements java.lang.Cloneable

A generic class for computing message digests. Instantiate a subclass to implement a particular message digest algorithm (e.g., MD5).

To use, call one or more update() methods in sequence, then call computeCurrent(). The result of the digest computation can then be obtained using the getDigestBits() method.

The init() method may be called to reset the digest to its initial state. The digestValid field indicates whether the value of digestBits is valid, that is, no calls to update() or init() have been made since the last call to computeCurrent().


Nested Class Summary
 class MessageDigest.MDState
          Class representing the current state of a message digest object.

 

Field Summary
protected  AlgorithmIdentifier algID
           
 byte[] digestBits
          The result of the hash computation.
 boolean digestValid
          Indicates whether the value of digestBits is valid.

 

Constructor Summary
protected MessageDigest()
          Creates a new message digest object.

 

Method Summary
abstract  java.lang.String algName()
          Returns the algorithm name of this message digest.
abstract  int blockSize()
           
abstract  java.lang.Object clone()
          Returns a clone of this message digest object.
abstract  void computeCurrent()
          Completes the hash computation, performing any necessary operations such as padding.
 byte[] computeDigest(byte[] source)
          Performs a complete digest operation on the given array of bytes.
 byte[] computeDigest(Streamable o)
           
abstract  AlgorithmIdentifier getAlgID()
           
 byte[] getDigestBits()
          Returns a copy of the current digest bytes.
abstract  int getDigestLength()
          Returns the length in bytes of the message digest.
static MessageDigest getInstance(AlgorithmIdentifier algID)
           
protected abstract  MessageDigest.MDState getState()
           
abstract  void init()
          Resets this message digest object to its initial state.
 boolean isEqual(byte[] otherDigest)
          Compares this digest to the specified digest for equality.
static boolean isEqual(byte[] digesta, byte[] digestb)
          Deprecated. Use Utils.areEqual(byte[], byte[]) instead.
 void setAlgID(AlgorithmIdentifier algID)
           
protected abstract  void setState(MessageDigest.MDState state)
           
 java.lang.String toString()
          Returns a string representation of this message digest object.
 void update(boolean aValue)
          Adds one byte to the data being digested, either 1 (if the given boolean value is true), or 0 (if the given boolean value is false).
abstract  void update(byte aValue)
          Adds the specifed byte to the data being digested.
 void update(byte[] input)
          Adds the specified array of bytes to the data being digested.
 void update(byte[] input, int off, int len)
          Adds the specified sequence of bytes to the data being digested.
 void update(java.io.InputStream in)
          Adds characters from the specified input stream to the data being digested, until end of stream is reached.
 void update(int aValue)
          Adds four bytes -- the big-endian representation of the specified int value -- to the data being digested.
 void update(int[] input)
          Adds the specified array of int values to the data being digested, using big-endian representation.
 void update(long aValue)
          Adds eight bytes -- the big-endian representation of the specified long value -- to the data being digested.
 void update(long[] input)
          Adds the specified array of long values to the data being digested, using big-endian representation.
 void update(short aValue)
          Adds two bytes -- the big-endian representation of the specified short value -- to the data being digested.
 void update(short[] input)
          Adds the specified array of short values to the data being digested, using big-endian representation.
 void update(java.lang.String input)
          Adds the characters of the specified string to the data being digested.
 void updateASCII(java.lang.String input)
          Adds the characters of the specified string to the data being digested.

 

Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Field Detail

digestBits

public byte[] digestBits
The result of the hash computation.

digestValid

public boolean digestValid
Indicates whether the value of digestBits is valid.

algID

protected AlgorithmIdentifier algID

Constructor Detail

MessageDigest

protected MessageDigest()
Creates a new message digest object. The message digest is initialized automatically.

Method Detail

setAlgID

public void setAlgID(AlgorithmIdentifier algID)
              throws AlgorithmIdentifierException
Throws:
AlgorithmIdentifierException

getAlgID

public abstract AlgorithmIdentifier getAlgID()

blockSize

public abstract int blockSize()

getInstance

public static MessageDigest getInstance(AlgorithmIdentifier algID)
                                 throws AlgorithmIdentifierException
Throws:
AlgorithmIdentifierException

init

public abstract void init()
Resets this message digest object to its initial state.

update

public abstract void update(byte aValue)
Adds the specifed byte to the data being digested.

update

public void update(boolean aValue)
Adds one byte to the data being digested, either 1 (if the given boolean value is true), or 0 (if the given boolean value is false).

update

public void update(short aValue)
Adds two bytes -- the big-endian representation of the specified short value -- to the data being digested.

update

public void update(int aValue)
Adds four bytes -- the big-endian representation of the specified int value -- to the data being digested.

update

public void update(long aValue)
Adds eight bytes -- the big-endian representation of the specified long value -- to the data being digested.

update

public void update(byte[] input,
                   int off,
                   int len)
Adds the specified sequence of bytes to the data being digested.
Parameters:
input - the input array
off - start position in the input array
len - the number of input array elements to add to the data being digested

update

public void update(byte[] input)
Adds the specified array of bytes to the data being digested.

update

public void update(short[] input)
Adds the specified array of short values to the data being digested, using big-endian representation.

update

public void update(int[] input)
Adds the specified array of int values to the data being digested, using big-endian representation.

update

public void update(long[] input)
Adds the specified array of long values to the data being digested, using big-endian representation.

update

public void update(java.lang.String input)
Adds the characters of the specified string to the data being digested.

Each character is treated as a 16-bit value, and is appended in big-endian order.


updateASCII

public void updateASCII(java.lang.String input)
Adds the characters of the specified string to the data being digested.

Each character is treated as a ISO-Latin1 (8-bit) character.


update

public void update(java.io.InputStream in)
            throws java.io.IOException
Adds characters from the specified input stream to the data being digested, until end of stream is reached.
Throws:
java.io.IOException

computeCurrent

public abstract void computeCurrent()
Completes the hash computation, performing any necessary operations such as padding. The result of the hash can be obtained using getDigestBits().

getDigestBits

public byte[] getDigestBits()
Returns a copy of the current digest bytes.

computeDigest

public byte[] computeDigest(byte[] source)
Performs a complete digest operation on the given array of bytes.

That is, first init() is called, then the byte array is given to update, then computeCurrent() is called.


computeDigest

public byte[] computeDigest(Streamable o)
                     throws java.io.IOException
Throws:
java.io.IOException

isEqual

public static boolean isEqual(byte[] digesta,
                              byte[] digestb)
Deprecated. Use Utils.areEqual(byte[], byte[]) instead.
Compares two digests for equality. Simple byte comparison.
Parameters:
digesta - the first digest bytes
digestb - the second digest bytes

isEqual

public boolean isEqual(byte[] otherDigest)
Compares this digest to the specified digest for equality. Simple byte comparison.

algName

public abstract java.lang.String algName()
Returns the algorithm name of this message digest.

getDigestLength

public abstract int getDigestLength()
Returns the length in bytes of the message digest.

toString

public java.lang.String toString()
Returns a string representation of this message digest object.

clone

public abstract java.lang.Object clone()
Returns a clone of this message digest object.

getState

protected abstract MessageDigest.MDState getState()

setState

protected abstract void setState(MessageDigest.MDState state)

Oracle Security Developer Tools Crypto Java API Reference
10g (10.1.4.0.1)

B28171-01


Copyright © 2005 ,2006 , Oracle. All rights reserved.