com.ibm.security.pkcs9
Class MessageDigest

java.lang.Object
  |
  +--com.ibm.security.pkcsutil.PKCSDerObject
        |
        +--com.ibm.security.pkcs9.PKCS9DerObject
              |
              +--com.ibm.security.pkcs9.MessageDigest

public final class MessageDigest
extends PKCS9DerObject
implements Cloneable

Implements the ASN.1 MessageDigest type.

A MessageDigest attribute must have a single attribute value.

MessageDigest ::= OCTET STRING

MessageDigest objects are immutable; they cannot be changed once created. If the setData() method is called and the MessageDigest value has already been set, the setData() method will throw a PKCSException.


Fields inherited from class com.ibm.security.pkcsutil.PKCSDerObject
provider
 
Constructor Summary
MessageDigest()
          Create an uninitialized MessageDigest object.
MessageDigest(byte[] der)
          Create a MessageDigest object with a DER byte array.
MessageDigest(byte[] digest, int dummy)
          Create a MessageDigest object with the input digest.
MessageDigest(byte[] digest, int dummy, String provider)
          Create a MessageDigest object with the input digest.
MessageDigest(byte[] der, String provider)
          Create a MessageDigest object with a DER byte array.
MessageDigest(String provider)
          Create an uninitialized MessageDigest object.
MessageDigest(String filename, boolean base64)
          Create a MessageDigest with the filename of the DER-encoded or BASE64-encoded object.
MessageDigest(String filename, boolean base64, String provider)
          Create a MessageDigest with the filename of the DER-encoded or BASE64-encoded object.
 
Method Summary
 Object clone()
          Creates a clone of this MessageDigest object.
protected  void decode(com.ibm.security.pkcs9.DerValue encoding)
          Initializes a MessageDigest object from a DerValue.
 void encode(OutputStream os)
          Encodes this object to an OutputStream.
 boolean equals(Object obj)
          Determines if this MessageDigest object is equivalent to the input object.
 String getAttributeName()
          Returns a String indicating the name of the attribute.
 byte[] getBytes()
          Returns a copy of the digest of this MessageDigest object.
 ObjectIdentifier getObjectIdentifier()
          Returns the ObjectIdentifer for the MessageDigest attribute.
 Object getValue()
          Calls the getBytes method.
 boolean isSingleValued()
          Returns true.
 boolean isTagValid(byte tag)
          Returns a boolean indicating if the tag is valid for this object.
 void setData(byte[] bytes)
          Set the message digest byte array for this MessageDigest object.
 String toString()
          Returns a string representation of this MessageDigest object.
 
Methods inherited from class com.ibm.security.pkcs9.PKCS9DerObject
getName, getOID, getPKCSAttribute
 
Methods inherited from class com.ibm.security.pkcsutil.PKCSDerObject
decode, decode, encode, hashCode, read, readBASE64, write, write, writeBASE64
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageDigest

public MessageDigest()
Create an uninitialized MessageDigest object. The message digest byte array for this uninitialized object can be set with the setData method.

MessageDigest

public MessageDigest(String provider)
Create an uninitialized MessageDigest object. The message digest byte array for this uninitialized object can be set with the setData method.

MessageDigest

public MessageDigest(byte[] der)
              throws IOException
Create a MessageDigest object with a DER byte array.
Parameters:
der - a DER byte array of a MessageDigest object.
Throws:
IOException - on decoding errors.

MessageDigest

public MessageDigest(byte[] der,
                     String provider)
              throws IOException
Create a MessageDigest object with a DER byte array.
Parameters:
der - a DER byte array of a MessageDigest object.
provider - the provider to be used.
Throws:
IOException - on decoding errors.

MessageDigest

public MessageDigest(byte[] digest,
                     int dummy)
              throws IOException
Create a MessageDigest object with the input digest. The second argument is ignored; it serves merely to differentiate constructor signatures.
Parameters:
digest - the message digest.
dummy - ignored; serves to differentiate the constructor signature.
Throws:
IOException - on decoding errors.

MessageDigest

public MessageDigest(byte[] digest,
                     int dummy,
                     String provider)
              throws IOException
Create a MessageDigest object with the input digest. The second argument is ignored; it serves merely to differentiate constructor signatures.
Parameters:
digest - the message digest.
dummy - ignored; serves to differentiate the constructor signature.
provider - the provider to be used.
Throws:
IOException - on decoding errors.

MessageDigest

public MessageDigest(String filename,
                     boolean base64)
              throws IOException
Create a MessageDigest with the filename of the DER-encoded or BASE64-encoded object.
Parameters:
filename - name of the DER-encoded or base64-encoded object
base64 - true if BASE64-encoded, false if DER-encoded
Throws:
IOException - on decoding errors.

MessageDigest

public MessageDigest(String filename,
                     boolean base64,
                     String provider)
              throws IOException
Create a MessageDigest with the filename of the DER-encoded or BASE64-encoded object.
Parameters:
filename - name of the DER-encoded or base64-encoded object
base64 - true if BASE64-encoded, false if DER-encoded
provider - the provider to be used
Throws:
IOException - on decoding errors.
Method Detail

clone

public Object clone()
Creates a clone of this MessageDigest object.
Overrides:
clone in class Object
Returns:
clone of this MessageDigest object.

equals

public boolean equals(Object obj)
Determines if this MessageDigest object is equivalent to the input object.
Overrides:
equals in class PKCSDerObject
Parameters:
other - the object to compare this one to.
Returns:
true, if the two objects are equivalent, false otherwise.

getObjectIdentifier

public ObjectIdentifier getObjectIdentifier()
Returns the ObjectIdentifer for the MessageDigest attribute.
Overrides:
getObjectIdentifier in class PKCSDerObject
Returns:
the ObjectIdentifer for the MessageDigest attribute.

encode

public void encode(OutputStream os)
            throws IOException
Encodes this object to an OutputStream.
Overrides:
encode in class PKCSDerObject
Parameters:
os - the OutputStream to write the encoded data to.
Throws:
IOException - on encoding errors.

setData

public void setData(byte[] bytes)
             throws PKCSException
Set the message digest byte array for this MessageDigest object.
Parameters:
bytes - byte array representation of the MessageDigest.
Throws:
PKCSException - if the byte array was already set.

getBytes

public byte[] getBytes()
Returns a copy of the digest of this MessageDigest object.
Returns:
byte array representation of the MessageDigest.

getValue

public Object getValue()
Calls the getBytes method. Standard method to access the value of the PKCS #9 object.
Overrides:
getValue in class PKCS9DerObject

isTagValid

public boolean isTagValid(byte tag)
Returns a boolean indicating if the tag is valid for this object.
Overrides:
isTagValid in class PKCS9DerObject
Returns:
true if tag_OctetString, false otherwise.

isSingleValued

public boolean isSingleValued()
Returns true. MessageDigest must have a single attribute value.
Overrides:
isSingleValued in class PKCS9DerObject
Returns:
true

getAttributeName

public String getAttributeName()
Returns a String indicating the name of the attribute.
Overrides:
getAttributeName in class PKCS9DerObject
Returns:
name of the MessageDigest attribute.

toString

public String toString()
Returns a string representation of this MessageDigest object.
Overrides:
toString in class PKCSDerObject
Returns:
a string representation of this object.

decode

protected void decode(com.ibm.security.pkcs9.DerValue encoding)
               throws IOException
Initializes a MessageDigest object from a DerValue. The DER encoding must be in the format specified by the MessageDigest ASN.1 notation.
Overrides:
decode in class PKCS9DerObject
Parameters:
encoding - a DER-encoded MessageDigest object.
Throws:
IOException - on parsing error.