public class

SealedObject

extends Object
implements Serializable
java.lang.Object
   ↳ javax.crypto.SealedObject

Class Overview

A SealedObject is a wrapper around a serializable object instance and encrypts it using a cryptographic cipher.

Since a SealedObject instance is a serializable object itself it can either be stored or transmitted over an insecure channel.

The wrapped object can later be decrypted (unsealed) using the corresponding key and then be deserialized to retrieve the original object.The sealed object itself keeps track of the cipher and corresponding parameters.

Summary

Fields
protected byte[] encodedParams The AlgorithmParameters in encoded format.
Public Constructors
SealedObject(Serializable object, Cipher c)
Creates a new SealedObject instance wrapping the specified object and sealing it using the specified cipher.
Protected Constructors
SealedObject(SealedObject so)
Creates a new SealedObject instance by copying the data from the specified object.
Public Methods
final String getAlgorithm()
Returns the algorithm this object was sealed with.
final Object getObject(Key key, String provider)
Returns the wrapped object, decrypting it using the specified key.
final Object getObject(Key key)
Returns the wrapped object, decrypting it using the specified key.
final Object getObject(Cipher c)
Returns the wrapped object, decrypting it using the specified cipher.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected byte[] encodedParams

Since: API Level 1

The AlgorithmParameters in encoded format.

Public Constructors

public SealedObject (Serializable object, Cipher c)

Since: API Level 1

Creates a new SealedObject instance wrapping the specified object and sealing it using the specified cipher.

The cipher must be fully initialized.

Parameters
object the object to seal, can be null.
c the cipher to encrypt the object.
Throws
IOException if the serialization fails.
IllegalBlockSizeException if the specified cipher is a block cipher and the length of the serialized data is not a multiple of the ciphers block size.
NullPointerException if the cipher is null.

Protected Constructors

protected SealedObject (SealedObject so)

Since: API Level 1

Creates a new SealedObject instance by copying the data from the specified object.

Parameters
so the object to copy.

Public Methods

public final String getAlgorithm ()

Since: API Level 1

Returns the algorithm this object was sealed with.

Returns
  • the algorithm this object was sealed with.

public final Object getObject (Key key, String provider)

Since: API Level 1

Returns the wrapped object, decrypting it using the specified key. The specified provider is used to retrieve the cipher algorithm.

Parameters
key the key to decrypt the data.
provider the name of the provider that provides the cipher algorithm.
Returns
  • the encapsulated object.
Throws
IOException if deserialization fails.
ClassNotFoundException if deserialization fails.
NoSuchAlgorithmException if the algorithm used to decrypt the data is not available.
NoSuchProviderException if the specified provider is not available.
InvalidKeyException if the specified key cannot be used to decrypt the data.

public final Object getObject (Key key)

Since: API Level 1

Returns the wrapped object, decrypting it using the specified key.

Parameters
key the key to decrypt the data with.
Returns
  • the encapsulated object.
Throws
IOException if deserialization fails.
ClassNotFoundException if deserialization fails.
NoSuchAlgorithmException if the algorithm to decrypt the data is not available.
InvalidKeyException if the specified key cannot be used to decrypt the data.

public final Object getObject (Cipher c)

Since: API Level 1

Returns the wrapped object, decrypting it using the specified cipher.

Parameters
c the cipher to decrypt the data.
Returns
  • the encapsulated object.
Throws
IOException if deserialization fails.
ClassNotFoundException if deserialization fails.
IllegalBlockSizeException if the specified cipher is a block cipher and the length of the serialized data is not a multiple of the ciphers block size.
BadPaddingException if the padding of the data does not match the padding scheme.