Skip navigation links

Oracle Security Developer Tools Crypto Java API Reference
11g (11.1.1)

E10668-02


oracle.security.crypto.core
Class MessageDigest

java.lang.Object
  extended by oracle.security.crypto.core.MessageDigest

All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
MAC, 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
          The algorithm identifier of this MessageDigest object.
 byte[] digestBits
          Deprecated. Use getDigestBits() instead.
 boolean digestValid
          Deprecated. Use isValid() instead.

 

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()
          Returns the blocksize of this instance.
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)
          Performs a complete digest operation on the given Streamable object.
abstract  AlgorithmIdentifier getAlgID()
          Returns the algorithm identifier of this object.
 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)
          Creates an instance of MessageDigest using the specified algorithm identifier.
protected abstract  MessageDigest.MDState getState()
          Gets the state of this MessageDigest instance.
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.
 boolean isValid()
          Returns true if this MessageDigest is in a valid state and its digest bits are usable; otherwise returns false.
 void setAlgID(AlgorithmIdentifier algID)
          Sets the AlgorithmIdentifier of this MessageDigest instance.
protected abstract  void setState(MessageDigest.MDState state)
          Sets the state of this MessageDigest instance.
 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 update(SymmetricKey key)
          Adds encoded representation of the symmetric key .
 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
Deprecated. Use getDigestBits() instead.
The result of the hash computation.

digestValid

public boolean digestValid
Deprecated. Use isValid() instead.
Indicates whether the value of digestBits is valid.

algID

protected AlgorithmIdentifier algID
The algorithm identifier of this MessageDigest object.

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
Sets the AlgorithmIdentifier of this MessageDigest instance.
Parameters:
algID - The AlgorithmIdentifier to use.
Throws:
AlgorithmIdentifierException

getAlgID

public abstract AlgorithmIdentifier getAlgID()
Returns the algorithm identifier of this object.
Returns:
An AlgorithIdentifier object representing the hash algorithm of this MessageDigest instance.

blockSize

public abstract int blockSize()
Returns the blocksize of this instance.

getInstance

public static MessageDigest getInstance(AlgorithmIdentifier algID)
                                 throws AlgorithmIdentifierException
Creates an instance of MessageDigest using the specified algorithm identifier.
Parameters:
algID - The AlgorithmIdentifier which will determine which concrete MessageDigest instance will be created.
Returns:
A new MessageDigest instance implementing the algorithm identifier specified in parameter.
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.


update

public void update(SymmetricKey key)
Adds encoded representation of the symmetric key .

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.

isValid

public boolean isValid()
Returns true if this MessageDigest is in a valid state and its digest bits are usable; otherwise returns false.

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
Performs a complete digest operation on the given Streamable object.

That is, first init() is called, then the Streamable object is given to update, then computeCurrent() is called.

Throws:
java.io.IOException

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.
Overrides:
toString in class java.lang.Object

clone

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

getState

protected abstract MessageDigest.MDState getState()
Gets the state of this MessageDigest instance.

setState

protected abstract void setState(MessageDigest.MDState state)
Sets the state of this MessageDigest instance.

Skip navigation links

Oracle Security Developer Tools Crypto Java API Reference
11g (11.1.1)

E10668-02


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