cryptix
Class MessageDigest

java.lang.Object
  |
  +--cryptix.MessageDigest
Direct Known Subclasses:
MD5

public abstract class MessageDigest
extends java.lang.Object

This is the abstract base class for all message digests.

Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) All rights reserved.

See Also:
java.crypt.MD5, java.crypt.SHA

Constructor Summary
protected MessageDigest()
          Both protected and abstract, so this class must be derived from in order to be useful.
 
Method Summary
 void add(byte[] data)
          Add a byte array to the digest
 void add(byte[] data, int offset, int length)
          Add a section of a byte array to the digest
 void add(java.lang.String message)
          Add the low bytes of a string to the digest (ie.
 void add(java.lang.String message, int offset, int length)
          Add the low bytes of a string to the digest (ie.
protected  void addToDigest(byte[] data, int off, int len)
          Add data to the message digest This method is protected to ensure that all parameters are valid at this point - essential if the parameters are passed to native functions.
 long bitcount()
          Return the number of bits added to the digest so far
 int buf_off()
           
 byte[] buf()
           
abstract  int data_length()
          /** Return the length (in bytes) of the block that this hash function operates on.
 byte[] digest()
          Obtain the digest
abstract  MessageHash digestAsHash()
          Obtain the digest as a Hash object
abstract  int hash_length()
          Return the hash length in bytes
static byte[] hash(byte[] message, MessageDigest md)
          A convenience function for hashing a byte array.
static byte[] hash(java.lang.String message, MessageDigest md)
          A convenience function for hashing a string.
 int length()
          Return the hash length in bytes
protected abstract  byte[] md_digest()
          Perform the final transformation
protected abstract  void md_reset()
          Reset the message digest
protected abstract  void md_transform()
          Perform a transformation
abstract  java.lang.String name()
          Return the message digest name
 void reset()
          Initialise (reset) the message digest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageDigest

protected MessageDigest()
Both protected and abstract, so this class must be derived from in order to be useful.
Method Detail

bitcount

public final long bitcount()
Return the number of bits added to the digest so far

buf

public final byte[] buf()

buf_off

public final int buf_off()

length

public int length()
Return the hash length in bytes

hash_length

public abstract int hash_length()
Return the hash length in bytes

data_length

public abstract int data_length()
/** Return the length (in bytes) of the block that this hash function operates on.

name

public abstract java.lang.String name()
Return the message digest name
Returns:
The name of the message digest.

reset

public final void reset()
Initialise (reset) the message digest.

md_reset

protected abstract void md_reset()
Reset the message digest

md_transform

protected abstract void md_transform()
Perform a transformation

md_digest

protected abstract byte[] md_digest()
Perform the final transformation

digest

public final byte[] digest()
Obtain the digest

N.B. this resets the digest.

Returns:
the digest of all the data added to the message digest.

digestAsHash

public abstract MessageHash digestAsHash()
Obtain the digest as a Hash object

N.B. this resets the digest.

Returns:
the Hash of all the data added to the message digest.

add

public final void add(java.lang.String message,
                      int offset,
                      int length)
Add the low bytes of a string to the digest (ie. treat the string as ASCII).
Parameters:
message - The string to add.
offset - The start of the data string.
length - The length of the data string.

add

public final void add(java.lang.String message)
Add the low bytes of a string to the digest (ie. treat the string as ASCII ).
Parameters:
message - The string to add.

add

public final void add(byte[] data)
Add a byte array to the digest
Parameters:
data - The data to be added.

add

public final void add(byte[] data,
                      int offset,
                      int length)
Add a section of a byte array to the digest
Parameters:
data - The data to add.
offset - The start of the data to add.
length - The length of the data to add.

addToDigest

protected final void addToDigest(byte[] data,
                                 int off,
                                 int len)
Add data to the message digest This method is protected to ensure that all parameters are valid at this point - essential if the parameters are passed to native functions.
Parameters:
data - The data to be added.
off - The start of the data in the array.
len - The amount of data to add.

hash

public static final byte[] hash(java.lang.String message,
                                MessageDigest md)
A convenience function for hashing a string.

eg:

 byte key[] = MessageDigest.hash( passPhrase, new MD5() ); 
Parameters:
message - The string to hash.
md - An instance of a message digest.
See Also:
MD5.hash(java.lang.String), SHA#hash(java.lang.String)

hash

public static final byte[] hash(byte[] message,
                                MessageDigest md)
A convenience function for hashing a byte array.

eg:

 byte key[] = MessageDigest.hash( bytearray, new MD5() ); 
Parameters:
message - The byte array to hash.
md - An instance of a message digest.
See Also:
MD5.hash(byte[]), SHA#hash(byte[])