com.ibm.security.pkcs12
Class CertBag

java.lang.Object
  |
  +--com.ibm.security.pkcsutil.PKCSDerObject
        |
        +--com.ibm.security.pkcs12.CertBag

public final class CertBag
extends PKCSDerObject
implements Bag, Cloneable

Implements the PKCS #12 CertBag data type, which is a container for for a certificate. X.509 and SDSI certificates are currently supported by the standard.

CertBag objects are immutable; they cannot be changed once created.


Fields inherited from class com.ibm.security.pkcsutil.PKCSDerObject
provider
 
Constructor Summary
CertBag(byte[] der)
          Create a CertBag with a DER byte array.
CertBag(byte[] der, String provider)
          Create a CertBag with a DER byte array.
CertBag(Certificate cert)
          Create a CertBag with the input Certificate.
CertBag(Certificate cert, String provider)
          Create a CertBag with the input Certificate.
CertBag(ObjectIdentifier oid, byte[] encoding)
          Create a CertBag with the input object identifier and certificate encoding.
CertBag(ObjectIdentifier oid, byte[] encoding, String provider)
          Create a CertBag with the input object identifier and certificate encoding.
CertBag(String filename, boolean base64)
          Create a CertBag with the filename of the DER-encoded or BASE64-encoded object.
CertBag(String filename, boolean base64, String provider)
          Create a CertBag with the filename of the DER-encoded or BASE64-encoded object.
 
Method Summary
 Object clone()
          Creates a clone of this CertBag object.
protected  void decode(com.ibm.security.pkcs12.DerValue encoding)
          Initialize a CertBag object from an input stream.
 void encode(OutputStream out)
          Encodes this object to a DER OutputStream.
 boolean equals(Object other)
          Determines if this CertBag object is equivalent to the input object.
 byte[] getEncodedValue()
          Returns the DER-encoded contents of this object.
 String getName()
          Returns the common name for this bag type: "CertBag".
 ObjectIdentifier getObjectIdentifier()
          Returns the object identifier for this PKCS #12 bag.
 Object getValue()
          Returns a copy of the contents of this PKCS #12 bag.
 String toString()
          Returns a string representation of this CertBag object.
 
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

CertBag

public CertBag(byte[] der)
        throws IOException
Create a CertBag with a DER byte array.

CertBag

public CertBag(byte[] der,
               String provider)
        throws IOException
Create a CertBag with a DER byte array.

CertBag

public CertBag(Certificate cert)
        throws PKCSException
Create a CertBag with the input Certificate.
Parameters:
cert - a Certificate object.
Throws:
PKCSException - if the certificate has an invalid format.

CertBag

public CertBag(Certificate cert,
               String provider)
        throws PKCSException
Create a CertBag with the input Certificate.
Parameters:
cert - a Certificate object.
Throws:
PKCSException - if the certificate has an invalid format.

CertBag

public CertBag(ObjectIdentifier oid,
               byte[] encoding)
Create a CertBag with the input object identifier and certificate encoding. The encoding must be the DER-encoding for an X.509 certificate if the OID is for an X.509 CertBag. The encoding must be the DER-encoding of an SDSI certificate if the OID is for an SDSI CertBag.
Parameters:
oid - an X.509 or SDSI CertBag object identifier.
encoding - a Certificate DER-encoding.
Throws:
IllegalArgumentException - if the OID or encoding is invalid.

CertBag

public CertBag(ObjectIdentifier oid,
               byte[] encoding,
               String provider)
Create a CertBag with the input object identifier and certificate encoding. The encoding must be the DER-encoding for an X.509 certificate if the OID is for an X.509 CertBag. The encoding must be the DER-encoding of an SDSI certificate if the OID is for an SDSI CertBag.
Parameters:
oid - an X.509 or SDSI CertBag object identifier.
encoding - a Certificate DER-encoding.
Throws:
IllegalArgumentException - if the OID or encoding is invalid.

CertBag

public CertBag(String filename,
               boolean base64)
        throws IOException
Create a CertBag 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.

CertBag

public CertBag(String filename,
               boolean base64,
               String provider)
        throws IOException
Create a CertBag 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

encode

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

getObjectIdentifier

public ObjectIdentifier getObjectIdentifier()
Returns the object identifier for this PKCS #12 bag.
Specified by:
getObjectIdentifier in interface Bag
Overrides:
getObjectIdentifier in class PKCSDerObject
Returns:
the ObjectIdentifier for this bag.

getValue

public Object getValue()
Returns a copy of the contents of this PKCS #12 bag. The type of the contents object is either an X.509 certificate object or a String representation of an SDSI certificate. Null may be returned if an error occurs creating the return certificate.
Specified by:
getValue in interface Bag
Returns:
the contents for this bag.

getEncodedValue

public byte[] getEncodedValue()
Returns the DER-encoded contents of this object.
Specified by:
getEncodedValue in interface Bag
Returns:
the DER-encoded certificate of this bag. Null may be returned if the certificate cannot be encoded.

getName

public String getName()
Returns the common name for this bag type: "CertBag".
Specified by:
getName in interface Bag
Returns:
the name of this bag.

equals

public boolean equals(Object other)
Determines if this CertBag 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.

clone

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

toString

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

decode

protected void decode(com.ibm.security.pkcs12.DerValue encoding)
               throws IOException
Initialize a CertBag object from an input stream. The data on that input stream must be a DER-encoded CertBag object.
Parameters:
encoding - an input stream with a DER-encoded CertBag object.
Throws:
IOException - on parsing errors.
IllegalArgumentException - if the encoded OID is invalid.