SealedObject (Java SE 11 & JDK 11 ) (original) (raw)
Field Detail
* #### encodedParams
protected byte[] encodedParams
The cryptographic parameters used by the sealing Cipher, encoded in the default format.
That is, `cipher.getParameters().getEncoded()`.
Constructor Detail
* #### SealedObject
public SealedObject([Serializable](../../java/io/Serializable.html "interface in java.io") object,
[Cipher](Cipher.html "class in javax.crypto") c)
throws [IOException](../../java/io/IOException.html "class in java.io"),
[IllegalBlockSizeException](IllegalBlockSizeException.html "class in javax.crypto")
Constructs a SealedObject from any Serializable object.
The given object is serialized, and its serialized contents are encrypted using the given Cipher, which must be fully initialized.
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; can be null.
`c` \- the cipher used to seal the object.
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the given cipher is null.
`[IOException](../../java/io/IOException.html "class in java.io")` \- if an error occurs during serialization
`[IllegalBlockSizeException](IllegalBlockSizeException.html "class in javax.crypto")` \- if the given cipher is a block cipher, no padding has been requested, and the total input length (i.e., the length of the serialized object contents) is not a multiple of the cipher's block size
* #### SealedObject
protected SealedObject([SealedObject](SealedObject.html "class in javax.crypto") so)
Constructs a SealedObject object from the passed-in SealedObject.
Parameters:
`so` \- a SealedObject object
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the given sealed object is null.
Method Detail
* #### getAlgorithm
public final [String](../../java/lang/String.html "class in java.lang") getAlgorithm()
Returns the algorithm that was used to seal this object.
Returns:
the algorithm that was used to seal this object.
* #### getObject
public final [Object](../../java/lang/Object.html "class in java.lang") getObject([Key](../../java/security/Key.html "interface in java.security") key)
throws [IOException](../../java/io/IOException.html "class in java.io"),
[ClassNotFoundException](../../java/lang/ClassNotFoundException.html "class in java.lang"),
[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security"),
[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")
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 initialized 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-serialized, before it is returned.
Parameters:
`key` \- the key used to unseal the object.
Returns:
the original object.
Throws:
`[IOException](../../java/io/IOException.html "class in java.io")` \- if an error occurs during de-serialiazation.
`[ClassNotFoundException](../../java/lang/ClassNotFoundException.html "class in java.lang")` \- if an error occurs during de-serialiazation.
`[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")` \- if the algorithm to unseal the object is not available.
`[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")` \- if the given key cannot be used to unseal the object (e.g., it has the wrong algorithm).
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if `key` is null.
* #### getObject
public final [Object](../../java/lang/Object.html "class in java.lang") getObject([Cipher](Cipher.html "class in javax.crypto") c)
throws [IOException](../../java/io/IOException.html "class in java.io"),
[ClassNotFoundException](../../java/lang/ClassNotFoundException.html "class in java.lang"),
[IllegalBlockSizeException](IllegalBlockSizeException.html "class in javax.crypto"),
[BadPaddingException](BadPaddingException.html "class in javax.crypto")
Retrieves the original (encapsulated) object.
The encapsulated object is unsealed (using the given Cipher, assuming that the Cipher is already properly initialized) and de-serialized, before it is returned.
Parameters:
`c` \- the cipher used to unseal the object
Returns:
the original object.
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the given cipher is null.
`[IOException](../../java/io/IOException.html "class in java.io")` \- if an error occurs during de-serialiazation
`[ClassNotFoundException](../../java/lang/ClassNotFoundException.html "class in java.lang")` \- if an error occurs during de-serialiazation
`[IllegalBlockSizeException](IllegalBlockSizeException.html "class in javax.crypto")` \- 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](BadPaddingException.html "class in javax.crypto")` \- if the given cipher has been initialized for decryption, and padding has been specified, but the input data does not have proper expected padding bytes
* #### getObject
public final [Object](../../java/lang/Object.html "class in java.lang") getObject([Key](../../java/security/Key.html "interface in java.security") key,
[String](../../java/lang/String.html "class in java.lang") provider)
throws [IOException](../../java/io/IOException.html "class in java.io"),
[ClassNotFoundException](../../java/lang/ClassNotFoundException.html "class in java.lang"),
[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security"),
[NoSuchProviderException](../../java/security/NoSuchProviderException.html "class in java.security"),
[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")
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 initialized 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-serialized, 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:
`[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if the given provider is null or empty.
`[IOException](../../java/io/IOException.html "class in java.io")` \- if an error occurs during de-serialiazation.
`[ClassNotFoundException](../../java/lang/ClassNotFoundException.html "class in java.lang")` \- if an error occurs during de-serialiazation.
`[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")` \- if the algorithm to unseal the object is not available.
`[NoSuchProviderException](../../java/security/NoSuchProviderException.html "class in java.security")` \- if the given provider is not configured.
`[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")` \- if the given key cannot be used to unseal the object (e.g., it has the wrong algorithm).
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if `key` is null.