com.sshtools.util
Class Hash

java.lang.Object
  |
  +--com.sshtools.util.Hash

public class Hash
extends java.lang.Object

Template helper class for Hash alogorithms, wraps the MessageDigest class from the java.security package

Version:
1.0
Author:
Lee David Painter ( lee@sshtools.com )

Constructor Summary
Hash(java.lang.String algorithm)
          Constructor for the Hash object
 
Method Summary
 byte[] doFinal()
          Description of the Method
 void putBigInteger(java.math.BigInteger bi)
          Puts a BigInteger into the hash.
 void putByte(byte b)
          Puts a byte into the hash
 void putBytes(byte[] data)
          Puts an array of bytes into the hash
 void putInt(int i)
          Puts an integer into the hash.
 void putString(java.lang.String str)
          Puts a string into the hash.
 void reset()
          Resets the hash;
static byte[] simple(byte[] data, java.lang.String algorithm)
          Puts the data into a new instance of the algorithm message digest and returns the output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hash

public Hash(java.lang.String algorithm)
     throws java.security.NoSuchAlgorithmException
Constructor for the Hash object

Parameters:
algorithm - The algorithm to use
Throws:
java.security.NoSuchAlgorithmException - Thrown if the algorithm is not supported
Method Detail

putString

public void putString(java.lang.String str)
Puts a string into the hash. Writes the length as an integer and then the string data

Parameters:
str - The string to hash

reset

public void reset()
Resets the hash;


putInt

public void putInt(int i)
Puts an integer into the hash.

Parameters:
i - The integer value

putBytes

public void putBytes(byte[] data)
Puts an array of bytes into the hash

Parameters:
data - The byte array to hash

putByte

public void putByte(byte b)
Puts a byte into the hash

Parameters:
b - The byte to hash

putBigInteger

public void putBigInteger(java.math.BigInteger bi)
Puts a BigInteger into the hash. Writes the length as an integer and then the BigInteger data

Parameters:
bi - The BigInteger to hash

simple

public static byte[] simple(byte[] data,
                            java.lang.String algorithm)
                     throws java.security.NoSuchAlgorithmException
Puts the data into a new instance of the algorithm message digest and returns the output.

Parameters:
data - The data to hash
algorithm - The algorithm to use
Returns:
The hash output
Throws:
java.security.NoSuchAlgorithmException - Thrown of the algorithm is not supported

doFinal

public byte[] doFinal()
Description of the Method

Returns:
Description of the Return Value


Copyright © 2002 Sshtools.com. All Rights Reserved.