com.ibm.security.pkcs12
Class SecretBag

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

public final class SecretBag
extends PKCSDerObject
implements Bag, Cloneable

Implements the PKCS #12 SecretBag data type.

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


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

SecretBag

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

SecretBag

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

SecretBag

public SecretBag(ObjectIdentifier oid,
                 byte[] obj)
Create a SecretBag with the input byte stream which must be the DER-encoding of some object.
Parameters:
oid - the object identifier of this secret bag.
obj - the DER-encoding of the bag contents object.

SecretBag

public SecretBag(ObjectIdentifier oid,
                 byte[] obj,
                 String provider)
Create a SecretBag with the input byte stream which must be the DER-encoding of some object.
Parameters:
oid - the object identifier of this secret bag.
obj - the DER-encoding of the bag contents object.
provider - the provider being used.

SecretBag

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

SecretBag

public SecretBag(String filename,
                 boolean base64,
                 String provider)
          throws IOException
Create a SecretBag 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 being 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 a copy of 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 a byte array which is the DER-encoding of an object.
Specified by:
getValue in interface Bag
Returns:
the contents for this bag, as a DER-encoding.

getEncodedValue

public byte[] getEncodedValue()
Returns the DER-encoding of the contents of this bag. For SecretBags, this method is equivalent to getValue.
Specified by:
getEncodedValue in interface Bag
Returns:
the DER-encoding of the contents of this bag.

getName

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

equals

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

toString

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