com.rsa.jsafe
Class JSAFE_MessageDigest

java.lang.Object
  extended bycom.rsa.jsafe.JSAFE_Object
      extended bycom.rsa.jsafe.JSAFE_MessageDigest
All Implemented Interfaces:
Cloneable, Serializable

public abstract class JSAFE_MessageDigest
extends JSAFE_Object
implements Cloneable, Serializable

This class instantiates the classes that create and verify signatures, and it defines the functionality. This class defines the factory methods and API for all message digest objects, which are also known as cryptographic hash functions.

See Overview of Crypto-J for background and reference material on using and understanding Crypto-J.

Note: Not all Crypto-J transformations have OIDs assigned to them. See Crypto-J Transformations and Their Associated Classes for a list of transformations that have assigned OIDs.

Copyright © RSA Security Inc., 1997-2005. All rights reserved.

See Also:
Serialized Form

Constructor Summary
JSAFE_MessageDigest()

 

 
Method Summary

static String

berDecodeAlgorithm(byte[] encoding, int encOffset)

Determines an algorithm, when given a BER encoding in encoding, beginning at encOffset.

static byte[]

berDecodeDigest(byte[] encoding, int encOffset)

Determines the digest, when given a BER encoding in encoding, beginning at encOffset.

 void

clearSensitiveData()

Clears sensitive data from an object.

 byte[]

derEncode(byte[] digest, int offset)

Creates the DER encoding when given a digest beginning at offset.

abstract  int

derEncode(byte[] digest, int digOffset, byte[] encoding, int encOffset)

Creates the DER encoding when given a digest beginning at digOffset, and places the result into encoding beginning at encOffset.

 byte[]

digestFinal()

Finalizes the process and returns the resulting digest in a new byte array.

abstract  int

digestFinal(byte[] output, int offset)

Finalizes the process and returns the resulting digest in a new byte array.

abstract  void

digestInit()

Initializes this object for a digest operation.

abstract  void

digestUpdate(byte[] partIn, int offset, int partInLen)

Digests the first partInLen bytes of the array partIn, beginning at offset.

abstract  String

getAlgorithm()

Returns the standard digest algorithm name.

abstract  byte[]

getDERAlgorithmID()

Returns a new byte array containing the DER encoding of the algorithm ID of the algorithm in this object.

 String

getDevice()

Returns the standard name of the device of record.

 String[]

getDeviceList()

Returns a String array that describes all the devices used to execute the transformation.

abstract  int

getDigestSize()

Returns the size, in bytes, of the resulting digest.

abstract  int

getEncodedDigestSize()

Returns the size, in bytes, of the DER encoding of the digest.

static JSAFE_MessageDigest

getInstance(byte[] berAlgID, int offset, String device)

Builds an object that performs an algorithm using the possible parameters defined in berAlgID beginning at offset.

static JSAFE_MessageDigest

getInstance(String transformation, String device)

Builds an object that performs the transformation on the given device.

static int

getNextBEROffset(byte[] berAlgID, int offset)

Gets the next offset after the algorithm ID.

 
Methods inherited from class com.rsa.jsafe.JSAFE_Object
clone, overwrite, overwrite
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSAFE_MessageDigest

public JSAFE_MessageDigest()
Method Detail

getInstance

public static JSAFE_MessageDigest getInstance(byte[] berAlgID,
                                              int offset,
                                              String device)
                                       throws JSAFE_UnimplementedException,
                                              JSAFE_InvalidParameterException
Builds an object that performs an algorithm using the possible parameters defined in berAlgID beginning at offset. This is the BER encoding of the algorithm identifier. The specified device is used.

Parameters:
berAlgID - A byte array containing the BER encoding of an algorithm ID.
offset - The offset into berAlgID where the encoding begins.
device - A list of devices used to build the object.
Returns:
A new JSAFE_MessageDigest object that performs the transformation as described by the algorithm ID.
Throws:
JSAFE_UnimplementedException - If the device or devices cannot perform the designated algorithm, or the toolkit cannot decode the BER encoding.
JSAFE_InvalidParameterException - If the BER encoding contains parameters that do not work.

getNextBEROffset

public static int getNextBEROffset(byte[] berAlgID,
                                   int offset)
                            throws JSAFE_UnimplementedException
Gets the next offset after the algorithm ID. Given the berAlgID, the BER encoding of the algorithm ID, beginning at offset, returns the index to the next byte in the array.

Parameters:
berAlgID - A byte array containing the BER encoding of an algorithm ID.
offset - The offset into berAlgID where the encoding begins.
Returns:
The index into berAlgID of the byte following the algorithm ID.
Throws:
JSAFE_UnimplementedException - If the toolkit cannot decode the BER encoding.

getInstance

public static JSAFE_MessageDigest getInstance(String transformation,
                                              String device)
                                       throws JSAFE_UnimplementedException,
                                              JSAFE_InvalidParameterException
Builds an object that performs the transformation on the given device.

Parameters:
transformation - The representation of the desired operation. The possible values for this string are: MD2, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, and RIPEMD160.
device - A list of devices used to build the object (for example, "Java", "Native/Java").
Returns:
A new JSAFE_MessageDigest object that performs the transformation.
Throws:
JSAFE_UnimplementedException - If the device or devices cannot perform the designated algorithm.
JSAFE_InvalidParameterException - If the transformation contains parameters that do not work.

getDERAlgorithmID

public abstract byte[] getDERAlgorithmID()
Returns a new byte array containing the DER encoding of the algorithm ID of the algorithm in this object.

Returns:
A new byte array that contains the algorithm ID.

getDevice

public String getDevice()
Returns the standard name of the device of record. Possible device names are as follows:

Returns:
The device name.

getDeviceList

public String[] getDeviceList()
Returns a String array that describes all the devices used to execute the transformation. Because a transformation often consists of component algorithms, the implementation can consist of several component objects. A device can perform one or more of the algorithms, but it may let Java or another device perform one or more. For example, because padding is not time-consuming, a device might let the Crypto-J implementation perform padding. Returns the name of the devices used by each component.

Returns:
A String array that describes the device used for a specific component.

getAlgorithm

public abstract String getAlgorithm()
Returns the standard digest algorithm name.

Returns:
A String describing the digest algorithm.

getDigestSize

public abstract int getDigestSize()
Returns the size, in bytes, of the resulting digest.

Returns:
An int that is the size of the output digest.

getEncodedDigestSize

public abstract int getEncodedDigestSize()
Returns the size, in bytes, of the DER encoding of the digest.

Returns:
An int that is the size of the encoded digest output.

digestInit

public abstract void digestInit()
Initializes this object for a digest operation.


digestUpdate

public abstract void digestUpdate(byte[] partIn,
                                  int offset,
                                  int partInLen)
                           throws JSAFE_InvalidUseException
Digests the first partInLen bytes of the array partIn, beginning at offset.

Parameters:
partIn - The data to digest.
offset - The offset into partIn where the data begins.
partInLen - The length of the data to digest.
Throws:
JSAFE_InvalidUseException - If the object is not initialized for a digest operation.

digestFinal

public byte[] digestFinal()
                   throws JSAFE_InvalidUseException
Finalizes the process and returns the resulting digest in a new byte array.

Returns:
A new byte array containing the digest.
Throws:
JSAFE_InvalidUseException - If the object is not initialized.

digestFinal

public abstract int digestFinal(byte[] output,
                                int offset)
                         throws JSAFE_InvalidUseException
Finalizes the process and returns the resulting digest in a new byte array.

Parameters:
output - The buffer where the output is placed.
offset - The offset into output where the writing begins.
Returns:
The number of bytes placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not initialized.

derEncode

public byte[] derEncode(byte[] digest,
                        int offset)
Creates the DER encoding when given a digest beginning at offset. Generates the DER encoding of the DigestInfo. The derEncode() method assumes the digest is for the algorithm given at instantiation. This method returns the encoding in a new byte array.

Use the following ASN.1 definition:

   DigestInfo ::= SEQUENCE {
     digestAlgorithm AlgorithmIdentifier,
     digest OCTET STRING }
 
This method considers the digest to be of the algorithm specified at instantiation. It uses as many of the bytes in the input buffer as the algorithm specifies.

Parameters:
digest - The digest to encode.
offset - The offset into digest where the value begins.
Returns:
A new byte array containing the encoded digest.

derEncode

public abstract int derEncode(byte[] digest,
                              int digOffset,
                              byte[] encoding,
                              int encOffset)
Creates the DER encoding when given a digest beginning at digOffset, and places the result into encoding beginning at encOffset. Generates the DER encoding of the DigestInfo. The derEncode() method assumes the digest is for the algorithm given at instantiation.

Use the following ASN.1 definition:

   DigestInfo ::= SEQUENCE {
     digestAlgorithm AlgorithmIdentifier,
     digest OCTET STRING }
 
Considers the digest to be the same as the algorithm specified at instantiation. It uses as many of the bytes in the input buffer as the algorithm specifies.

Parameters:
digest - The digest to encode.
digOffset - The offset into digest where the value begins.
encoding - The buffer where the output is placed.
encOffset - The offset into encoding where the writing begins.
Returns:
The number of bytes placed into the output buffer.

berDecodeAlgorithm

public static String berDecodeAlgorithm(byte[] encoding,
                                        int encOffset)
                                 throws JSAFE_InputException
Determines an algorithm, when given a BER encoding in encoding, beginning at encOffset. It returns the standard name of the algorithm. Given the encoding, determines which digest algorithm is represented.

Use the following ASN.1 definition:

   DigestInfo ::= SEQUENCE {
     digestAlgorithm AlgorithmIdentifier,
     digest OCTET STRING }
 

Parameters:
encoding - The BER encoding to decode.
encOffset - The offset into encoding where the data begins.
Returns:
The standard name of the algorithm.
Throws:
JSAFE_InputException - If the encoding is not a known digest algorithm.

berDecodeDigest

public static byte[] berDecodeDigest(byte[] encoding,
                                     int encOffset)
                              throws JSAFE_InputException
Determines the digest, when given a BER encoding in encoding, beginning at encOffset. It returns a new byte array. Note this is a static method.

Use the following ASN.1 definition:

   DigestInfo ::= SEQUENCE {
     digestAlgorithm AlgorithmIdentifier,
     digest OCTET STRING }
 

Parameters:
encoding - The BER encoding to decode.
encOffset - The offset into encoding where the data begins.
Returns:
A new byte array containing the decoded digest.
Throws:
JSAFE_InputException - If the encoding is not a known digest algorithm.

clearSensitiveData

public void clearSensitiveData()
Clears sensitive data from an object. Although the finalizer clears the data, there is no guarantee the garbage collector will quickly call the finalizer. Allows a user to clear data as soon as possible. After calling clearSensitiveData(), an Init (not a ReInit) method is called to perform other operations with the object.



RSA BSAFE Crypto-J 3.5.2