com.motorola.iden.security
Class MessageDigest

java.lang.Object
  |
  +--com.motorola.iden.security.MessageDigestSpi
        |
        +--com.motorola.iden.security.MessageDigest
Direct Known Subclasses:
MD5, SHA

public abstract class MessageDigest
extends MessageDigestSpi

This MessageDigest class provides applications the functionality of a message digest algorithm, such as MD5 or SHA. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

A MessageDigest object starts out initialized. The data is processed through it using the update methods. At any point reset can be called to reset the digest. Once all the data to be updated has been updated, one of the digest methods should be called to complete the hash computation.

The digest method can be called once for a given number of updates. After digest has been called, the MessageDigest object is reset to its initialized state.

 MessageDigest md;

 try {
     md = MessageDigest.getInstance("MD5");
     md.update(toChapter1);
     md.update(toChapter2);
     byte[] toChapter1Digest = md.digest();
     etc.
 } catch (NoSuchAlgorithmException) {}
 

Note that this class is abstract and extends from MessageDigestSpi for historical reasons. Application developers should only take notice of the methods defined in this MessageDigest class; all the methods in the superclass are intended for cryptographic service providers who wish to supply their own implementations of message digest algorithms.

MOTOROLA and the Stylized M Logo are registered trademarks of Motorola, Inc. Reg. U.S. Pat. & Tm. Off.
© Copyright 2002 - 2004 Motorola, Inc. All Rights Reserved.

See Also:
[MessageDigestSpi]

Constructor Summary
MessageDigest()
           
 
Method Summary
 byte[] digest()
          Completes the hash computation by performing final operations such as padding.
 java.lang.String getAlgorithm()
          Returns a string that identifies the algorithm, independent of implementation details.
 int getDigestLength()
          Returns the length of the digest in bytes, or 0 if this operation is not supported by the provider and the implementation is not cloneable.
static MessageDigest getInstance(java.lang.String algorithm)
          Generates a MessageDigest object that implements the specified digest algorithm.
static MessageDigest getInstance(java.lang.String algorithm, java.lang.String usrPackage)
          Generates a MessageDigest object that implements the specified digest algorithm.
 void reset()
          Resets the digest for further use.
 void update(byte input)
          Updates the digest using the specified byte.
 void update(byte[] input, int offset, int len)
          Updates the digest using the specified array of bytes, starting at the specified offset.
 
Methods inherited from class com.motorola.iden.security.MessageDigestSpi
engineDigest, engineGetDigestLength, engineReset, engineUpdate, engineUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageDigest

public MessageDigest()
Method Detail

getInstance

public static MessageDigest getInstance(java.lang.String algorithm)
                                 throws NoSuchAlgorithmException
Generates a MessageDigest object that implements the specified digest algorithm.

If the default provider package provides an implementation of the requested digest algorithm, an instance of MessageDigest containing that implementation is returned. If the algorithm is not available in the default package, NoSuchAlgorithmException would be thrown.

Parameters:
algorithm - the name of the algorithm requested. MD5 and SHA are supported in current implementation.
Returns:
a Message Digest object implementing the specified algorithm.
Throws:
NoSuchAlgorithmException - if the algorithm is not available in the default package.

getInstance

public static MessageDigest getInstance(java.lang.String algorithm,
                                        java.lang.String usrPackage)
                                 throws NoSuchAlgorithmException
Generates a MessageDigest object that implements the specified digest algorithm.

If the default provider package provides an implementation of the requested digest algorithm, an instance of MessageDigest containing that implementation is returned. If the algorithm is not available in the default package, other packages are searched.

Parameters:
algorithm - the name of the algorithm requested. MD5 and SHA are supported in current implementation.
usrPackage - the package which the end user provided algorithm belongs to.
Returns:
a Message Digest object implementing the specified algorithm.
Throws:
NoSuchAlgorithmException - if the algorithm is not available in usrPackage..

update

public void update(byte input)
Updates the digest using the specified byte.
Parameters:
input - the byte with which to update the digest.

update

public void update(byte[] input,
                   int offset,
                   int len)
Updates the digest using the specified array of bytes, starting at the specified offset.
Parameters:
input - the array of bytes.
offset - the offset to start from in the array of bytes.
len - the number of bytes to use, starting at offset.

digest

public byte[] digest()
Completes the hash computation by performing final operations such as padding. The digest is reset after this call is made.
Returns:
the array of bytes for the resulting hash value.

reset

public void reset()
Resets the digest for further use.

getAlgorithm

public final java.lang.String getAlgorithm()
Returns a string that identifies the algorithm, independent of implementation details. The name should be a standard Java Security name (such as "SHA", "MD5", and so on).
Returns:
the name of the algorithm

getDigestLength

public final int getDigestLength()
Returns the length of the digest in bytes, or 0 if this operation is not supported by the provider and the implementation is not cloneable.
Returns:
the digest length in bytes, or 0 if this operation is not supported by the provider and the implementation is not cloneable.