de.bb.security
Class MessageDigest

java.lang.Object
  |
  +--de.bb.security.MessageDigest
Direct Known Subclasses:
MD5, MDC2, RMD160, SHA

public abstract class MessageDigest
extends java.lang.Object

This class is copied from Sun's source for java.security.MessageDigest because it's not shipped with Netscape's JVM


Constructor Summary
protected MessageDigest(java.lang.String name)
          Creates a message digest with the specified algorithm name.
 
Method Summary
abstract  java.lang.Object clone()
           
 byte[] digest()
          Completes the hash computation by performing final operations such as padding.
 byte[] digest(byte[] input)
          Performs a final update on the digest using the specified array of bytes, then completes the digest computation.
protected abstract  byte[] engineDigest()
          SPI: Completes the hash computation by performing final operations such as padding.
protected abstract  void engineReset()
          SPI: Resets the digest for further use.
protected abstract  void engineUpdate(byte input)
          SPI: Updates the digest using the specified byte.
protected  void engineUpdate(byte[] b, int off, int len)
          add the given part of the byte array to rge digest
 java.lang.String getAlgorithm()
          Returns a string that identifies the algorithm, independent of implementation details.
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 provider)
          Generates a MessageDigest object implementing the specified algorithm, as supplied from the specified provider, if such an algorithm is available from the provider.
 byte[] hmac(byte[] k, byte[] t1, byte[] t2, byte[] t3, byte[] t4, byte[] t5)
          create some hash bytes
formula: MD(k ^ 0x5C, MD(k ^ 0x36, t1+t2+t3+t4+t5))
tested on MD5-test-vectors found in RFC 2104
static boolean isEqual(byte[] digesta, byte[] digestb)
          Compares two digests for equality.
 void reset()
          Resets the digest for further use.
protected static int rol(int value, int bits)
          rotate the given value to left side
 void update(byte input)
          Updates the digest using the specified byte.
 void update(byte[] input)
          Updates the digest using the specified array of bytes.
 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 java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageDigest

protected MessageDigest(java.lang.String name)
Creates a message digest with the specified algorithm name.
Parameters:
algorithm - the standard name of the digest algorithm. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.
Method Detail

digest

public final 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.

digest

public final byte[] digest(byte[] input)
Performs a final update on the digest using the specified array of bytes, then completes the digest computation. That is, this method first calls update on the array, then calls digest().
Parameters:
input - the input to be updated before the digest is completed.
Returns:
the array of bytes for the resulting hash value.

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). See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.

getInstance

public static MessageDigest getInstance(java.lang.String algorithm)
                                 throws java.lang.Exception
Generates a MessageDigest object that implements the specified digest algorithm. If the default provider package contains a MessageDigest subclass implementing the algorithm, an instance of that subclass is returned. If the algorithm is not available in the default package, other packages are searched.
Parameters:
algorithm - the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.
Returns:
a Message Digest object implementing the specified algorithm.
Throws:
NoSuchAlgorithmException - if the algorithm is not available in the caller's environment.

getInstance

public static MessageDigest getInstance(java.lang.String algorithm,
                                        java.lang.String provider)
                                 throws java.lang.Exception
Generates a MessageDigest object implementing the specified algorithm, as supplied from the specified provider, if such an algorithm is available from the provider.
Parameters:
algorithm - the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.
provider - the name of the provider.
Returns:
a Message Digest object implementing the specified algorithm.
Throws:
NoSuchAlgorithmException - if the algorithm is not available in the package supplied by the requested provider.
NoSuchProviderException - if the provider is not available in the environment.
See Also:
Provider

isEqual

public static boolean isEqual(byte[] digesta,
                              byte[] digestb)
Compares two digests for equality. Does a simple byte compare.
Parameters:
digesta - one of the digests to compare.
digestb - the other digest to compare.
Returns:
true if the digests are equal, false otherwise.

reset

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

update

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

update

public final 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.

update

public final void update(byte[] input)
Updates the digest using the specified array of bytes.
Parameters:
input - the array of bytes.

engineDigest

protected abstract byte[] engineDigest()
SPI: Completes the hash computation by performing final operations such as padding. Once engineDigest has been called, the engine should be reset (see reset). Resetting is the responsibility of the engine implementor.
Returns:
the array of bytes for the resulting hash value.

engineReset

protected abstract void engineReset()
SPI: Resets the digest for further use.

engineUpdate

protected abstract void engineUpdate(byte input)
SPI: Updates the digest using the specified byte.
Parameters:
input - the byte to use for the update.

engineUpdate

protected void engineUpdate(byte[] b,
                            int off,
                            int len)
add the given part of the byte array to rge digest
Parameters:
b - the byte array whichs data is added
off - offset into the array
len - count of bytes which are added

rol

protected static final int rol(int value,
                               int bits)
rotate the given value to left side
Parameters:
value - - value to by rotateted left
bist - - count of bits to rotate left

hmac

public final byte[] hmac(byte[] k,
                         byte[] t1,
                         byte[] t2,
                         byte[] t3,
                         byte[] t4,
                         byte[] t5)
create some hash bytes
formula: MD(k ^ 0x5C, MD(k ^ 0x36, t1+t2+t3+t4+t5))
tested on MD5-test-vectors found in RFC 2104
Parameters:
md - MessageDigest
k - key-parameter(see formula)
t1..t5 - text parameters(see formula)
Returns:
a new allocated byte array containing the hash bytes

clone

public abstract java.lang.Object clone()
Overrides:
clone in class java.lang.Object