Skip to content

Most visited

Recently visited

navigation
Added in API level 1

SealedObject

public class SealedObject
extends Object implements Serializable

java.lang.Object
   ↳ javax.crypto.SealedObject


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

Since a SealedObject instance is serializable 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 cipher's 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)

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

final Object getObject(Key key, String provider)

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.

Inherited methods

From class java.lang.Object

Fields

encodedParams

Added in API level 1
byte[] encodedParams

The cipher's AlgorithmParameters in encoded format. Equivalent to cipher.getParameters().getEncoded(), or null if the cipher did not use any parameters.

Public constructors

SealedObject

Added in API level 1
SealedObject (Serializable object, 
                Cipher c)

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

The cipher must be fully initialized.

Parameters
object Serializable: the object to seal, can be null.
c Cipher: 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

SealedObject

Added in API level 1
SealedObject (SealedObject so)

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

Parameters
so SealedObject: the object to copy.

Public methods

getAlgorithm

Added in API level 1
String getAlgorithm ()

Returns the algorithm this object was sealed with.

Returns
String the algorithm this object was sealed with.

getObject

Added in API level 1
Object getObject (Key key)

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

Parameters
key Key: the key to decrypt the data with.
Returns
Object 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.

getObject

Added in API level 1
Object getObject (Key key, 
                String provider)

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

Parameters
key Key: the key to decrypt the data.
provider String: the name of the provider that provides the cipher algorithm.
Returns
Object 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.

getObject

Added in API level 1
Object getObject (Cipher c)

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

Parameters
c Cipher: the cipher to decrypt the data.
Returns
Object 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.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.