Most visited

Recently visited

Added in API level 1

ExemptionMechanism

public class ExemptionMechanism
extends Object

java.lang.Object
   ↳ javax.crypto.ExemptionMechanism


这个课程提供了豁免机制的功能,其中的例子是 关键恢复关键弱化密钥托管

使用豁免机制的应用程序或小应用程序可能被授予更强大的加密功能。

Summary

Protected constructors

ExemptionMechanism(ExemptionMechanismSpi exmechSpi, Provider provider, String mechanism)

创建一个ExemptionMechanism对象。

Public methods

final int genExemptionBlob(byte[] output)

生成豁免机制密钥blob,并将结果存储在 output缓冲区中。

final byte[] genExemptionBlob()

生成豁免机制密钥blob。

final int genExemptionBlob(byte[] output, int outputOffset)

生成豁免机制密钥blob,并将结果存储在 output缓冲区中,从 outputOffset含)开始。

static final ExemptionMechanism getInstance(String algorithm)

返回实现指定豁免机制算法的 ExemptionMechanism对象。

static final ExemptionMechanism getInstance(String algorithm, String provider)

返回实现指定豁免机制算法的 ExemptionMechanism对象。

static final ExemptionMechanism getInstance(String algorithm, Provider provider)

返回实现指定豁免机制算法的 ExemptionMechanism对象。

final String getName()

返回此 ExemptionMechanism对象的豁免机制名称。

final int getOutputSize(int inputLen)

给定输入长度 inputLen (以字节为单位),返回输出缓冲区需要保留下一个 genExemptionBlob操作结果 inputLen的字节长度。

final Provider getProvider()

返回此 ExemptionMechanism对象的提供者。

final void init(Key key, AlgorithmParameters params)

使用密钥和一组算法参数初始化此免除机制。

final void init(Key key, AlgorithmParameterSpec params)

使用密钥和一组算法参数初始化此免除机制。

final void init(Key key)

使用密钥初始化此免除机制。

final boolean isCryptoAllowed(Key key)

通过此免除机制返回结果blob是否已成功生成。

Protected methods

void finalize()

确保在没有更多引用时,由此ExemptionMechanism对象存储的密钥将被清除。

Inherited methods

From class java.lang.Object

Protected constructors

ExemptionMechanism

Added in API level 1
ExemptionMechanism (ExemptionMechanismSpi exmechSpi, 
                Provider provider, 
                String mechanism)

创建一个ExemptionMechanism对象。

Parameters
exmechSpi ExemptionMechanismSpi: the delegate
provider Provider: the provider
mechanism String: the exemption mechanism

Public methods

genExemptionBlob

Added in API level 1
int genExemptionBlob (byte[] output)

生成豁免机制密钥blob,并将结果存储在 output缓冲区中。

如果output缓冲区太小而无法保存结果, ShortBufferException抛出ShortBufferException 在这种情况下,使用更大的输出缓冲区重复此调用。 使用getOutputSize来确定输出缓冲区应该有多大。

Parameters
output byte: the buffer for the result
Returns
int the number of bytes stored in output
Throws
IllegalStateException if this exemption mechanism is in a wrong state (e.g., has not been initialized).
ShortBufferException if the given output buffer is too small to hold the result.
ExemptionMechanismException if problem(s) encountered in the process of generating.

genExemptionBlob

Added in API level 1
byte[] genExemptionBlob ()

生成豁免机制密钥blob。

Returns
byte[] the new buffer with the result key blob.
Throws
IllegalStateException if this exemption mechanism is in a wrong state (e.g., has not been initialized).
ExemptionMechanismException if problem(s) encountered in the process of generating.

genExemptionBlob

Added in API level 1
int genExemptionBlob (byte[] output, 
                int outputOffset)

生成豁免机制密钥blob,并将结果存储在 output缓冲区中,从 outputOffset开始(包括 outputOffset

如果output缓冲区太小而无法保存结果, ShortBufferException抛出ShortBufferException 在这种情况下,使用更大的输出缓冲区重复此调用。 使用getOutputSize来确定输出缓冲区应该有多大。

Parameters
output byte: the buffer for the result
outputOffset int: the offset in output where the result is stored
Returns
int the number of bytes stored in output
Throws
IllegalStateException if this exemption mechanism is in a wrong state (e.g., has not been initialized).
ShortBufferException if the given output buffer is too small to hold the result.
ExemptionMechanismException if problem(s) encountered in the process of generating.

getInstance

Added in API level 1
ExemptionMechanism getInstance (String algorithm)

返回实现指定豁免机制算法的 ExemptionMechanism对象。

该方法遍历注册安全提供程序的列表,从最优先的提供程序开始。 返回一个新的ExemptionMechanism对象,该对象封装来自支持指定算法的第一个Provider的ExemptionMechanismSpi实现。

请注意,注册供应商列表可能通过 Security.getProviders()方法检索。

Parameters
algorithm String: the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard exemption mechanism names.
Returns
ExemptionMechanism the new ExemptionMechanism object.
Throws
NullPointerException if algorithm is null.
NoSuchAlgorithmException if no Provider supports an ExemptionMechanismSpi implementation for the specified algorithm.

也可以看看:

getInstance

Added in API level 1
ExemptionMechanism getInstance (String algorithm, 
                String provider)

返回实现指定豁免机制算法的 ExemptionMechanism对象。

返回一个新的ExemptionMechanism对象,封装来自指定提供者的ExemptionMechanismSpi实现。 指定的提供者必须在安全提供者列表中注册。

请注意,注册供应商列表可能通过 Security.getProviders()方法检索。

Parameters
algorithm String: the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard exemption mechanism names.
provider String: the name of the provider.
Returns
ExemptionMechanism the new ExemptionMechanism object.
Throws
NullPointerException if algorithm is null.
NoSuchAlgorithmException if an ExemptionMechanismSpi implementation for the specified algorithm is not available from the specified provider.
NoSuchProviderException if the specified provider is not registered in the security provider list.
IllegalArgumentException if the provider is null or empty.

也可以看看:

getInstance

Added in API level 1
ExemptionMechanism getInstance (String algorithm, 
                Provider provider)

返回实现指定豁免机制算法的 ExemptionMechanism对象。

返回一个新的ExemptionMechanism对象,封装来自指定Provider对象的ExemptionMechanismSpi实现。 请注意,指定的Provider对象不必在提供程序列表中注册。

Parameters
algorithm String: the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard exemption mechanism names.
provider Provider: the provider.
Returns
ExemptionMechanism the new ExemptionMechanism object.
Throws
NullPointerException if algorithm is null.
NoSuchAlgorithmException if an ExemptionMechanismSpi implementation for the specified algorithm is not available from the specified Provider object.
IllegalArgumentException if the provider is null.

也可以看看:

getName

Added in API level 1
String getName ()

返回此 ExemptionMechanism对象的豁免机制名称。

这与在创建此 ExemptionMechanism对象的 getInstance调用之一中指定的名称相同。

Returns
String the exemption mechanism name of this ExemptionMechanism object.

getOutputSize

Added in API level 1
int getOutputSize (int inputLen)

给定输入长度 inputLen (以字节为单位),返回输出缓冲区需要保留下一个 genExemptionBlob操作结果 inputLen的字节长度。

下一个 genExemptionBlob调用的实际输出长度可能小于此方法返回的长度。

Parameters
inputLen int: the input length (in bytes)
Returns
int the required output buffer size (in bytes)
Throws
IllegalStateException if this exemption mechanism is in a wrong state (e.g., has not yet been initialized)

getProvider

Added in API level 1
Provider getProvider ()

返回此 ExemptionMechanism对象的提供者。

Returns
Provider the provider of this ExemptionMechanism object.

init

Added in API level 1
void init (Key key, 
                AlgorithmParameters params)

使用密钥和一组算法参数初始化此免除机制。

如果此免除机制需要任何算法参数且params为空,则基础豁免机制实现本身应该生成所需的参数(使用提供程序特定的缺省值); 在算法参数必须由调用者指定的情况下,引发InvalidAlgorithmParameterException

Parameters
key Key: the key for this exemption mechanism
params AlgorithmParameters: the algorithm parameters
Throws
InvalidKeyException if the given key is inappropriate for this exemption mechanism.
InvalidAlgorithmParameterException if the given algorithm parameters are inappropriate for this exemption mechanism.
ExemptionMechanismException if problem(s) encountered in the process of initializing.

init

Added in API level 1
void init (Key key, 
                AlgorithmParameterSpec params)

使用密钥和一组算法参数初始化此免除机制。

如果这个免除机制需要任何算法参数并且params为空,则底层免除机制实现本身应该生成所需的参数(使用特定于提供者的默认值); 在算法参数必须由调用者指定的情况下,引发InvalidAlgorithmParameterException

Parameters
key Key: the key for this exemption mechanism
params AlgorithmParameterSpec: the algorithm parameters
Throws
InvalidKeyException if the given key is inappropriate for this exemption mechanism.
InvalidAlgorithmParameterException if the given algorithm parameters are inappropriate for this exemption mechanism.
ExemptionMechanismException if problem(s) encountered in the process of initializing.

init

Added in API level 1
void init (Key key)

使用密钥初始化此免除机制。

如果此免除机制需要任何不能从给定的key派生的算法参数,则基础豁免机制实现本身应该生成所需的参数(使用特定于提供者的默认值); 在算法参数必须由调用者指定的情况下,引发InvalidKeyException

Parameters
key Key: the key for this exemption mechanism
Throws
InvalidKeyException if the given key is inappropriate for this exemption mechanism.
ExemptionMechanismException if problem(s) encountered in the process of initializing.

isCryptoAllowed

Added in API level 1
boolean isCryptoAllowed (Key key)

通过此免除机制返回结果blob是否已成功生成。

该方法还确保传入的密钥与此初始化和生成阶段中使用的免除机制相同。

Parameters
key Key: the key the crypto is going to use.
Returns
boolean whether the result blob of the same key has been generated successfully by this exemption mechanism; false if key is null.
Throws
ExemptionMechanismException if problem(s) encountered while determining whether the result blob has been generated successfully by this exemption mechanism object.

Protected methods

finalize

Added in API level 1
void finalize ()

确保在没有更多引用时,由此ExemptionMechanism对象存储的密钥将被清除。

Hooray!