cryptix.security
Class MessageDigest

java.lang.Object
  |
  +--cryptix.security.MessageDigest
Direct Known Subclasses:
MD5, SHA, SHA0

public abstract class MessageDigest
extends java.lang.Object

This is the abstract superclass for message digests that support the Cryptix V2.2 API. New code should use java.security.MessageDigest in preference.

Note: the following methods are no longer supported (starting from Cryptix 2.2.2), because they either have no JCE equivalent, or were part of the implementation of MessageDigest and should not have been public.

Copyright © 1995-1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.3 $

Since:
Cryptix 2.2
Author:
Systemics Ltd, David Hopwood
See Also:
MessageDigest

Constructor Summary
protected MessageDigest(java.security.MessageDigest md)
          Deprecated. Constructs a V2.2 message digest from a JCA message digest.
 
Method Summary
 void add(byte[] data)
          Deprecated. Use update(data) instead.
 void add(byte[] data, int offset, int length)
          Deprecated. Use update(data, offset, length).
 void add(java.lang.String message)
          Deprecated. Use update(cryptix.mime.LegacyString.toByteArray(message)) instead.
 void add(java.lang.String message, int offset, int length)
          Deprecated. Use update(cryptix.mime.LegacyString.toByteArray(message, offset, length)) instead.
 byte[] digest()
          Deprecated.  
 byte[] digest(byte[] data)
          Deprecated.  
 MessageHash digestAsHash()
          Deprecated. Replace md.digestAsHash() with MessageHash.fromDigest(md).
 int hash_length()
          Deprecated. Use getDigestLength() instead.
static byte[] hash(byte[] data, MessageDigest md)
          Deprecated. Use md.digest(data) instead.
static byte[] hash(java.lang.String message, MessageDigest md)
          Deprecated.  
 int length()
          Deprecated. Use getDigestLength() instead.
 java.lang.String name()
          Deprecated. Use getAlgorithm() instead.
 void reset()
          Deprecated.  
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageDigest

protected MessageDigest(java.security.MessageDigest md)
Deprecated. 
Constructs a V2.2 message digest from a JCA message digest.
Parameters:
md - the java.security.MessageDigest object.
Method Detail

hash_length

public final int hash_length()
Deprecated. Use getDigestLength() instead.

Returns the digest length in bytes.

The JCA equivalent to this method, java.security.MessageDigest.getDigestLength, is only supported when the IJCE version of the java.security.MessageDigest class is first on the classpath. getDigestLength will also be supported by Java 1.2.


length

public final int length()
Deprecated. Use getDigestLength() instead.

Identical to hash_length.

name

public final java.lang.String name()
Deprecated. Use getAlgorithm() instead.

Returns the message digest name.

digestAsHash

public final MessageHash digestAsHash()
Deprecated. Replace md.digestAsHash() with MessageHash.fromDigest(md).

Obtains a MessageHash object for this digest.

N.B. this method resets the digest.

Returns:
the MessageHash of all the data added.
See Also:
MessageHash

add

public final void add(java.lang.String message,
                      int offset,
                      int length)
Deprecated. Use update(cryptix.mime.LegacyString.toByteArray(message, offset, length)) instead.

Adds the low bytes of a string to the digest. This should not be used when internationalization is a concern, since it does not handle Unicode characters above \u00FF gracefully.
Parameters:
message - the string to add.
offset - the start of the data string.
length - the length of the data string.
Throws:
NullPointerException - if message == null
StringIndexOutOfBoundsException - if offset or length are out of range

add

public final void add(java.lang.String message)
Deprecated. Use update(cryptix.mime.LegacyString.toByteArray(message)) instead.

Adds the low bytes of a string to the digest. This should not be used when internationalization is a concern, since it does not handle Unicode characters above \u00FF gracefully.
Parameters:
message - the string to add.
Throws:
NullPointerException - if message == null

add

public final void add(byte[] data)
Deprecated. Use update(data) instead.

Adds a byte array to the digest.
Parameters:
data - the data to be added.
Throws:
NullPointerException - if data == null

add

public final void add(byte[] data,
                      int offset,
                      int length)
Deprecated. Use update(data, offset, length).

Adds 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.
Throws:
NullPointerException - if data == null
ArrayIndexOutOfBoundsException - if offset or length are out of range

digest

public final byte[] digest(byte[] data)
Deprecated. 

digest

public final byte[] digest()
Deprecated. 

reset

public final void reset()
Deprecated. 

hash

public static byte[] hash(java.lang.String message,
                          MessageDigest md)
Deprecated.  

A convenience function for hashing the low bytes of a string. This should not be used when internationalization is a concern, since it does not handle Unicode characters above \u00FF gracefully.

E.g.:

   import cryptix.security.MessageDigest;
 
byte[] key = MessageDigest.hash(passphrase, new SHA());
which should be replaced with:
   import java.security.MessageDigest;
   import cryptix.mime.LegacyString;
 
MessageDigest sha = MessageDigest.getInstance("SHA-1"); byte[] key = sha.digest(LegacyString.toByteArray(passphrase));
or (better for new applications, but not completely compatible):
   ...
   byte[] key = sha.digest(passphrase.getBytes("UTF8"));
 
Parameters:
message - the string to hash.
md - an instance of a message digest.

hash

public static byte[] hash(byte[] data,
                          MessageDigest md)
Deprecated. Use md.digest(data) instead.

A convenience function for hashing a byte array.

E.g.:

   import cryptix.security.MessageDigest;
 
byte[] key = MessageDigest.hash(bytearray, new SHA());
which should be replaced with
   import java.security.MessageDigest;
 
MessageDigest sha = MessageDigest.getInstance("SHA-1"); byte[] key = sha.digest(bytearray);
Parameters:
message - the byte array to hash
md - an instance of a message digest