javax.crypto
Class SealedObject

java.lang.Object
  |
  +--javax.crypto.SealedObject

public class SealedObject
extends java.lang.Object
implements java.io.Serializable

This class enables a programmer to create an object and protect its confidentiality with a cryptographic algorithm.

Given any Serializable object, one can create a SealedObject that encapsulates the original object, in serialised format (i.e., a "deep copy"), and seals (encrypts) its serialised contents, using a cryptographic algorithm such as DES, to protect its confidentiality. The encrypted content can later be decrypted (with the corresponding algorithm using the correct decryption key) and de-serialised, yielding the original object.

Note that the Cipher object must be fully initialised with the correct algorithm, key, padding scheme, etc., before being applied to a SealedObject.

The original object that was sealed can be recovered in two different ways:

by using the getObject method that takes a Cipher object.

This method requires a fully initialised Cipher object, initialised with the exact same algorithm, key, padding scheme, etc., that were used to seal the object.

This approach has the advantage that the party who unseals the sealed object does not require knowledge of the decryption key. For example, after one party has initialised the cipher object with the required decryption key, it could hand over the cipher object to another party who then unseals the sealed object.

by using one of the get Object methods that take a Key object.

In this approach, the getObject method creates a cipher object for the appropriate decryption algorithm and initialises it with the given decryption key and the algorithm parameters (if any) that were stored in the sealed object.

This approach has the advantage that the party who unseals the object does not need to keep track of the parameters (e.g., an IV) that were used to seal the object.

See Also:
Serialized Form

Constructor Summary
SealedObject(java.io.Serializable object, Cipher c)
          Constructs a SealedObject from any Serializable object.
 
Method Summary
 java.lang.String getAlgorithm()
          Returns the algorithm that was used to seal this object.
 java.lang.Object getObject(Cipher c)
          Retrieves the original (encapsulated) object.
 java.lang.Object getObject(java.security.Key key)
          Retrieves the original (encapsulated) object.
 java.lang.Object getObject(java.security.Key key, java.lang.String provider)
          Retrieves the original (encapsulated) object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SealedObject

public SealedObject(java.io.Serializable object,
                    Cipher c)
             throws java.io.IOException,
                    IllegalBlockSizeException
Constructs a SealedObject from any Serializable object.

The given object is sealed using the given Cipher, assuming that the Cipher is already properly initialised.

Any algorithm parameters that may be used in the encryption operation are stored inside of the new SealedObject.

Parameters:
object - - the object to be sealed.
c - - the cipher used to seal the object.
Throws:
java.io.IOException - if an error occurs during serialisation
IllegalBlockSizeException - if the given cipher is a block cipher, no padding has been requested, and the total input length is not a multiple of the cipher's block size.
Method Detail

getAlgorithm

public final java.lang.String getAlgorithm()
Returns the algorithm that was used to seal this object.
Returns:
the algorithm that was used to seal this object.

getObject

public final java.lang.Object getObject(java.security.Key key)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException,
                                        java.security.NoSuchAlgorithmException,
                                        java.security.InvalidKeyException
Retrieves the original (encapsulated) object.

This method creates a cipher for the algorithm that had been used in the sealing operation. If the default provider package provides an implementation of that algorithm, an instance of Cipher containing that implementation is used. If the algorithm is not available in the default package, other packages are searched. The Cipher object is initialised for decryption, using the given key and the parameters (if any) that had been used in the sealing operation.

The encapsulated object is unsealed and de-serialised, before it is returned.

Parameters:
key - the key used to unseal the object.
Returns:
the original object.
Throws:
java.io.IOException - if an error occurs during de-serialisation.
java.lang.ClassNotFoundException - if an error occurs during de-serialisation.
java.security.NoSuchAlgorithmException - if the algorithm to unseal the object is not available.
java.security.InvalidKeyException - if the given key cannot be used to unseal the object (e.g., it has the wrong algorithm).

getObject

public final java.lang.Object getObject(Cipher c)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException,
                                        IllegalBlockSizeException,
                                        BadPaddingException
Retrieves the original (encapsulated) object.

The encapsulated object is unsealed (using the given Cipher, assuming that the Cipher is already properly initialised) and de-serialised, before it is returned.

Parameters:
c - the cipher used to unseal the object
Returns:
the original object.
Throws:
java.io.IOException - if an error occurs during de-serialisation
java.lang.ClassNotFoundException - if an error occurs during de-serialisation.
IllegalBlockSizeException - if the given cipher is a block cipher, no padding has been requested, and the total input length is not a multiple of the cipher's block size.
BadPaddingException - if the given cipher has been initialised for decryption, and padding has been specified, but the input data does not have proper expected padding bytes.

getObject

public final java.lang.Object getObject(java.security.Key key,
                                        java.lang.String provider)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException,
                                        java.security.NoSuchAlgorithmException,
                                        java.security.NoSuchProviderException,
                                        java.security.InvalidKeyException
Retrieves the original (encapsulated) object.

This method creates a cipher for the algorithm that had been used in the sealing operation, using an implementation of that algorithm from the given provider. The Cipher object is initialised for decryption, using the given key and the parameters (if any) that had been used in the sealing operation.

The encapsulated object is unsealed and de-serialised, before it is returned.

Parameters:
key - the key used to unseal the object.
provider - the name of the provider of the algorithm to unseal the object.
Returns:
the original object.
Throws:
java.io.IOException - - if an error occurs during de-serialisation.
java.lang.ClassNotFoundException - if an error occurs during de-serialisation.
java.security.NoSuchAlgorithmException - if the algorithm to unseal the object is not available.
java.security.NoSuchProviderException - if the given provider is not configured.
java.security.InvalidKeyException - if the given key cannot be used to unseal the object (e.g., it has the wrong algorithm).