cryptix.security
Class MessageHash

java.lang.Object
  extended bycryptix.security.MessageHash
Direct Known Subclasses:
HashMD5, HashSHA, HashSHA0

public class MessageHash
extends java.lang.Object

This class represents the output from a message digest, in a form where the type can be ascertained.

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

$Revision: 1.3 $

Since:
Cryptix 2.2 (was abstract before 2.2.2)
Author:
Systemics Ltd, David Hopwood

Constructor Summary
MessageHash(java.lang.String algorithm, byte[] hash)
          Constructs a MessageHash for the specified algorithm name.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Tests whether this object is equal to another object.
static MessageHash fromDigest(MessageDigest md)
          Creates a MessageHash with the value found by calling the digest() method on md.
static MessageHash fromDigest(MessageDigest md, byte[] data)
          Creates a MessageHash with the value found by calling the digest(byte[]) method on md.
 java.lang.String getAlgorithm()
          Returns the name of the algorithm associated with this hash.
 int hashCode()
           
 int length()
          Returns the hash length in bytes.
 byte[] toByteArray()
          Returns the hash as a new byte array.
 java.lang.String toString()
          Returns a big endian Hex string showing the value of the hash, prefixed by the standard algorithm name and a colon.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageHash

public MessageHash(java.lang.String algorithm,
                   byte[] hash)
Constructs a MessageHash for the specified algorithm name. The hash value is a copy of the byte array hash.

Parameters:
algorithm - the name of the MessageDigest algorithm.
hash - a byte array containing the hash.
Throws:
java.lang.NullPointerException - if algorithm == null || hash == null
Method Detail

fromDigest

public static MessageHash fromDigest(MessageDigest md)
Creates a MessageHash with the value found by calling the digest() method on md. This causes md to be reset. It is equivalent to:
    new MessageHash(md.name(), md.digest())
 


fromDigest

public static MessageHash fromDigest(MessageDigest md,
                                     byte[] data)
Creates a MessageHash with the value found by calling the digest(byte[]) method on md. This causes md to be reset. It is equivalent to:
    new MessageHash(md.name(), md.digest(data))
 


getAlgorithm

public java.lang.String getAlgorithm()
Returns the name of the algorithm associated with this hash.


toByteArray

public final byte[] toByteArray()
Returns the hash as a new byte array.


length

public final int length()
Returns the hash length in bytes.


hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object obj)
Tests whether this object is equal to another object.

Two MessageHash objects are equal iff they are for the same algorithm, and have the same value as a sequence of bytes.

Returns:
true iff the objects are equal

toString

public java.lang.String toString()
Returns a big endian Hex string showing the value of the hash, prefixed by the standard algorithm name and a colon.

Returns:
a string representing the hash.