Most visited

Recently visited

Added in API level 1

SealedObject

public class SealedObject
extends Object implements Serializable

java.lang.Object
   ↳ javax.crypto.SealedObject


该类使程序员能够使用加密算法创建对象并保护其机密性。

给定任何Serializable对象,可以使用DES等加密算法以序列化格式(即“深层复制”)创建封装原始对象的SealedObject,并对其序列化内容进行封装(加密),以保护其机密性。 稍后可以对加密的内容进行解密(使用正确的解密密钥的相应算法)并对其进行解序列化,产生原始对象。

请注意,在应用到SealedObject之前,密码对象必须使用正确的算法,密钥,填充方案等完全初始化。

被密封的原始对象可以通过两种不同的方式恢复:

也可以看看:

Summary

Fields

protected byte[] encodedParams

密码密码使用的密码参数,默认格式编码。

Public constructors

SealedObject(Serializable object, Cipher c)

从任何可序列化对象构造一个SealedObject。

Protected constructors

SealedObject(SealedObject so)

从传入的SealedObject构造一个SealedObject对象。

Public methods

final String getAlgorithm()

返回用于密封此对象的算法。

final Object getObject(Key key, String provider)

检索原始(封装)对象。

final Object getObject(Key key)

检索原始(封装)对象。

final Object getObject(Cipher c)

检索原始(封装)对象。

Inherited methods

From class java.lang.Object

Fields

encodedParams

Added in API level 1
byte[] encodedParams

密码密码使用的密码参数,默认格式编码。

那就是 cipher.getParameters().getEncoded()

Public constructors

SealedObject

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

从任何可序列化对象构造一个SealedObject。

给定的对象是序列化的,其序列化的内容使用给定的密码进行加密,密码必须完全初始化。

任何可用于加密操作的算法参数都存储在新的 SealedObject内部。

Parameters
object Serializable: the object to be sealed; can be null.
c Cipher: the cipher used to seal the object.
Throws
NullPointerException if the given cipher is null.
IOException if an error occurs during serialization
IllegalBlockSizeException 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

Protected constructors

SealedObject

Added in API level 1
SealedObject (SealedObject so)

从传入的SealedObject构造一个SealedObject对象。

Parameters
so SealedObject: a SealedObject object
Throws
NullPointerException if the given sealed object is null.

Public methods

getAlgorithm

Added in API level 1
String getAlgorithm ()

返回用于密封此对象的算法。

Returns
String the algorithm that was used to seal this object.

getObject

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

检索原始(封装)对象。

此方法为密封操作中使用的算法创建了一个密码,并使用该算法从给定的provider 使用给定的key和在密封操作中使用的参数(如果有的话),密码对象被初始化用于解密。

被封装的对象在返回之前被解封并解序列化。

Parameters
key Key: the key used to unseal the object.
provider String: the name of the provider of the algorithm to unseal the object.
Returns
Object the original object.
Throws
IllegalArgumentException if the given provider is null or empty.
IOException if an error occurs during de-serialiazation.
ClassNotFoundException if an error occurs during de-serialiazation.
NoSuchAlgorithmException if the algorithm to unseal the object is not available.
NoSuchProviderException if the given provider is not configured.
InvalidKeyException if the given key cannot be used to unseal the object (e.g., it has the wrong algorithm).
NullPointerException if key is null.

getObject

Added in API level 1
Object getObject (Key key)

检索原始(封装)对象。

此方法为密封操作中使用的算法创建密码。 如果默认提供程序包提供该算法的实现,则使用包含该实现的Cipher实例。 如果该算法在默认包中不可用,则搜索其他包。 密码对象被初始化用于解密,使用给定的key和密封操作中使用的参数(如果有的话)。

被封装的对象在返回之前被解封并解序列化。

Parameters
key Key: the key used to unseal the object.
Returns
Object the original object.
Throws
IOException if an error occurs during de-serialiazation.
ClassNotFoundException if an error occurs during de-serialiazation.
NoSuchAlgorithmException if the algorithm to unseal the object is not available.
InvalidKeyException if the given key cannot be used to unseal the object (e.g., it has the wrong algorithm).
NullPointerException if key is null.

getObject

Added in API level 1
Object getObject (Cipher c)

检索原始(封装)对象。

被封装的对象在返回之前被解密(使用给定的Cipher,假定Cipher已经正确初始化)并且被反序列化。

Parameters
c Cipher: the cipher used to unseal the object
Returns
Object the original object.
Throws
NullPointerException if the given cipher is null.
IOException if an error occurs during de-serialiazation
ClassNotFoundException if an error occurs during de-serialiazation
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 initialized for decryption, and padding has been specified, but the input data does not have proper expected padding bytes

Hooray!