Package javax.crypto
Class SealedObject
- java.lang.Object
-
- javax.crypto.SealedObject
-
- All Implemented Interfaces:
Serializable
public class SealedObject extends Object implements Serializable
ASealedObjectis a wrapper around aserializableobject instance and encrypts it using a cryptographic cipher.Since a
SealedObjectinstance 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.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]encodedParamsThe cipher'sAlgorithmParametersin encoded format.
-
Constructor Summary
Constructors Modifier Constructor Description SealedObject(Serializable object, Cipher c)Creates a newSealedObjectinstance wrapping the specified object and sealing it using the specified cipher.protectedSealedObject(SealedObject so)Creates a newSealedObjectinstance by copying the data from the specified object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetAlgorithm()Returns the algorithm this object was sealed with.ObjectgetObject(Key key)Returns the wrapped object, decrypting it using the specified key.ObjectgetObject(Key key, String provider)Returns the wrapped object, decrypting it using the specified key.ObjectgetObject(Cipher c)Returns the wrapped object, decrypting it using the specified cipher.
-
-
-
Field Detail
-
encodedParams
protected byte[] encodedParams
The cipher'sAlgorithmParametersin encoded format. Equivalent tocipher.getParameters().getEncoded(), or null if the cipher did not use any parameters.
-
-
Constructor Detail
-
SealedObject
public SealedObject(Serializable object, Cipher c) throws IOException, IllegalBlockSizeException
Creates a newSealedObjectinstance wrapping the specified object and sealing it using the specified cipher.The cipher must be fully initialized.
- Parameters:
object- the object to seal, can benull.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 isnull.
-
SealedObject
protected SealedObject(SealedObject so)
Creates a newSealedObjectinstance by copying the data from the specified object.- Parameters:
so- the object to copy.
-
-
Method Detail
-
getAlgorithm
public final String getAlgorithm()
Returns the algorithm this object was sealed with.- Returns:
- the algorithm this object was sealed with.
-
getObject
public final Object getObject(Key key) throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeyException
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.
-
getObject
public final Object getObject(Cipher c) throws IOException, ClassNotFoundException, IllegalBlockSizeException, BadPaddingException
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.
-
getObject
public final Object getObject(Key key, String provider) throws IOException, ClassNotFoundException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException
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.
-
-