com.ibm.security.pkcs12
Class SafeBag

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

public final class SafeBag
extends PKCSDerObject
implements Cloneable

Implements the PKCS #12 SafeBag type. A SafeBag consists of one particular piece of personal information (a certificate, a key, etc) and optional attributes. PKCS #12, version 1.0 defines six types of SafeBags: KeyBag, ShroudedKeyBag, CertBag, CRLBag, SecretBag and SafeContentsBag.

SafeBag ::= SEQUENCE { bagId ObjectIdentifier, bagValue [0] EXPLICIT ANY DEFINED BY bagId, bagAttributes SET OF Attribute OPTIONAL }

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


Fields inherited from class com.ibm.security.pkcsutil.PKCSDerObject
provider
 
Constructor Summary
SafeBag(Bag bag, PKCSAttributes attrs)
          Create a SafeBag from a given bag type and attributes.
SafeBag(Bag bag, PKCSAttributes attrs, String provider)
          Create a SafeBag from a given bag type and attributes.
SafeBag(byte[] der)
          Create a SafeBag subclass with a DER byte array.
SafeBag(byte[] der, String provider)
          Create a SafeBag subclass with a DER byte array.
SafeBag(String filename, boolean base64)
          Create a SafeBag with the filename of the DER-encoded or BASE64-encoded object.
SafeBag(String filename, boolean base64, String provider)
          Create a SafeBag with the filename of the DER-encoded or BASE64-encoded object.
 
Method Summary
 SafeBag addAttributes(PKCSAttribute[] attrs)
          Adds one or more attributes to the object and returns the result in a new SafeBag object.
 Object clone()
          Creates a clone of this SafeBag object.
protected  void decode(com.ibm.security.pkcs12.DerValue encoding)
          Initialize a SafeBag object from an input stream.
 void encode(OutputStream out)
          Encodes this object to a DER OutputStream.
 boolean equals(Object other)
          Determines if this SafeBag object is equivalent to the input object.
 PKCSAttributes getAttributes()
          Returns a copy of the PKCSAttributes associated with this object, or null if there are no attributes.
 ObjectIdentifier getObjectIdentifier()
          Returns a copy of the object identifier of this SafeBag.
 byte[] getValue()
          Returns the DER-encoding of this SafeBag's content.
 SafeBag replaceAttributes(PKCSAttributes attrs)
          Replaces the attributes on this object and returns the result in a new SafeBag object.
 String toString()
          Returns a string representation of this SafeBag 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

SafeBag

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

SafeBag

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

SafeBag

public SafeBag(Bag bag,
               PKCSAttributes attrs)
        throws IOException
Create a SafeBag from a given bag type and attributes.

SafeBag

public SafeBag(Bag bag,
               PKCSAttributes attrs,
               String provider)
        throws IOException
Create a SafeBag from a given bag type and attributes.

SafeBag

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

SafeBag

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

addAttributes

public SafeBag addAttributes(PKCSAttribute[] attrs)
Adds one or more attributes to the object and returns the result in a new SafeBag object. This original object remains unchanged.
Parameters:
attrs - the PKCS attributes to be added.

replaceAttributes

public SafeBag replaceAttributes(PKCSAttributes attrs)
Replaces the attributes on this object and returns the result in a new SafeBag object. This original object remains unchanged.
Parameters:
attrs - the PKCS attributes to associate with this object.

getAttributes

public PKCSAttributes getAttributes()
Returns a copy of the PKCSAttributes associated with this object, or null if there are no attributes.
Returns:
a copy of the PKCSAttributes associated with this object, or null if there are none.

getObjectIdentifier

public ObjectIdentifier getObjectIdentifier()
Returns a copy of the object identifier of this SafeBag.
Overrides:
getObjectIdentifier in class PKCSDerObject
Returns:
the object identifier of this SafeBag.

getValue

public byte[] getValue()
Returns the DER-encoding of this SafeBag's content. This may be a DER-encoding of just the private information (for example, a private key or encrypted private key), or it may be the DER-encoding of a bag containing the private information (for example, a CertBag or CRLBag). In the latter case, the private information can be extracted from this inner bag.
Returns:
the DER-encoding of this SafeBag's content.

equals

public boolean equals(Object other)
Determines if this SafeBag 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 SafeBag object.
Overrides:
clone in class Object
Returns:
clone of this SafeBag object.

toString

public String toString()
Returns a string representation of this SafeBag 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 SafeBag object from an input stream. The data on that input stream must be a DER-encoded SafeBag object.
Parameters:
encoding - an input stream with a DER-encoded SafeBag object.
Throws:
IOException - on parsing errors.