public class ExemptionMechanism
extends Object
| java.lang.Object | |
| javax.crypto.ExemptionMechanism | |
这个课程提供了豁免机制的功能,其中的例子是 关键恢复 , 关键弱化和 密钥托管 。
使用豁免机制的应用程序或小应用程序可能被授予更强大的加密功能。
Protected constructors |
|
|---|---|
ExemptionMechanism(ExemptionMechanismSpi exmechSpi, Provider provider, String mechanism) 创建一个ExemptionMechanism对象。 |
|
公共方法(Public methods) |
|
|---|---|
final int |
genExemptionBlob(byte[] output) 生成豁免机制密钥blob,并将结果存储在 |
final byte[] |
genExemptionBlob() 生成豁免机制密钥blob。 |
final int |
genExemptionBlob(byte[] output, int outputOffset) 生成豁免机制密钥blob,并将结果存储在 |
static final ExemptionMechanism |
getInstance(String algorithm) 返回实现指定豁免机制算法的 |
static final ExemptionMechanism |
getInstance(String algorithm, String provider) 返回实现指定豁免机制算法的 |
static final ExemptionMechanism |
getInstance(String algorithm, Provider provider) 返回实现指定豁免机制算法的 |
final String |
getName() 返回此 |
final int |
getOutputSize(int inputLen) 给定输入长度 |
final Provider |
getProvider() 返回此 |
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) |
|
|---|---|
java.lang.Object
|
|
ExemptionMechanism (ExemptionMechanismSpi exmechSpi, Provider provider, String mechanism)
创建一个ExemptionMechanism对象。
| 参数(Parameters) | |
|---|---|
exmechSpi |
ExemptionMechanismSpi: the delegate |
provider |
Provider: the provider |
mechanism |
String: the exemption mechanism |
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. |
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. |
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. |
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. |
也可以看看:
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. |
也可以看看:
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. |
也可以看看:
String getName ()
返回此 ExemptionMechanism对象的豁免机制名称。
这与在创建此 ExemptionMechanism对象的 getInstance调用之一中指定的名称相同。
| 返回(Returns) | |
|---|---|
String |
the exemption mechanism name of this ExemptionMechanism object. |
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) |
Provider getProvider ()
返回此 ExemptionMechanism对象的提供者。
| 返回(Returns) | |
|---|---|
Provider |
the provider of this ExemptionMechanism object. |
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. |
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. |
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. |
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. |