ExemptionMechanism (Java SE 11 & JDK 11 ) (original) (raw)
Constructor Detail
* #### ExemptionMechanism
protected ExemptionMechanism([ExemptionMechanismSpi](ExemptionMechanismSpi.html "class in javax.crypto") exmechSpi,
[Provider](../../java/security/Provider.html "class in java.security") provider,
[String](../../java/lang/String.html "class in java.lang") mechanism)
Creates a ExemptionMechanism object.
Parameters:
`exmechSpi` \- the delegate
`provider` \- the provider
`mechanism` \- the exemption mechanism
Method Detail
* #### getName
public final [String](../../java/lang/String.html "class in java.lang") getName()
Returns the exemption mechanism name of this`ExemptionMechanism` object.
This is the same name that was specified in one of the`getInstance` calls that created this`ExemptionMechanism` object.
Returns:
the exemption mechanism name of this`ExemptionMechanism` object.
* #### getInstance
public static final [ExemptionMechanism](ExemptionMechanism.html "class in javax.crypto") getInstance([String](../../java/lang/String.html "class in java.lang") algorithm)
throws [NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")
Returns an `ExemptionMechanism` object that implements the specified exemption mechanism algorithm.
This method traverses the list of registered security Providers, starting with the most preferred Provider. A new ExemptionMechanism object encapsulating the ExemptionMechanismSpi implementation from the first Provider that supports the specified algorithm is returned.
Note that the list of registered providers may be retrieved via the [Security.getProviders()](../../java/security/Security.html#getProviders%28%29) method.
Implementation Note:
The JDK Reference Implementation additionally uses the`jdk.security.provider.preferred` [Security](../../java/security/Security.html#getProperty%28java.lang.String%29) property to determine the preferred provider order for the specified algorithm. This may be different than the order of providers returned by[Security.getProviders()](../../java/security/Security.html#getProviders%28%29).
Parameters:
`algorithm` \- the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the[ Java Security Standard Algorithm Names Specification](../../../../specs/security/standard-names.html#exemption-mechanisms) for information about standard exemption mechanism names.
Returns:
the new `ExemptionMechanism` object
Throws:
`[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")` \- if no `Provider` supports an`ExemptionMechanismSpi` implementation for the specified algorithm
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if `algorithm` is `null`
See Also:
[Provider](../../java/security/Provider.html "class in java.security")
* #### getInstance
public static final [ExemptionMechanism](ExemptionMechanism.html "class in javax.crypto") getInstance([String](../../java/lang/String.html "class in java.lang") algorithm,
[String](../../java/lang/String.html "class in java.lang") provider)
throws [NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security"),
[NoSuchProviderException](../../java/security/NoSuchProviderException.html "class in java.security")
Returns an `ExemptionMechanism` object that implements the specified exemption mechanism algorithm.
A new ExemptionMechanism object encapsulating the ExemptionMechanismSpi implementation from the specified provider is returned. The specified provider must be registered in the security provider list.
Note that the list of registered providers may be retrieved via the [Security.getProviders()](../../java/security/Security.html#getProviders%28%29) method.
Parameters:
`algorithm` \- the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the[ Java Security Standard Algorithm Names Specification](../../../../specs/security/standard-names.html#exemption-mechanisms) for information about standard exemption mechanism names.
`provider` \- the name of the provider.
Returns:
the new `ExemptionMechanism` object
Throws:
`[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if the `provider` is `null` or empty
`[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")` \- if an `ExemptionMechanismSpi` implementation for the specified algorithm is not available from the specified provider
`[NoSuchProviderException](../../java/security/NoSuchProviderException.html "class in java.security")` \- if the specified provider is not registered in the security provider list
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if `algorithm` is `null`
See Also:
[Provider](../../java/security/Provider.html "class in java.security")
* #### getInstance
public static final [ExemptionMechanism](ExemptionMechanism.html "class in javax.crypto") getInstance([String](../../java/lang/String.html "class in java.lang") algorithm,
[Provider](../../java/security/Provider.html "class in java.security") provider)
throws [NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")
Returns an `ExemptionMechanism` object that implements the specified exemption mechanism algorithm.
A new ExemptionMechanism object encapsulating the ExemptionMechanismSpi implementation from the specified Provider object is returned. Note that the specified Provider object does not have to be registered in the provider list.
Parameters:
`algorithm` \- the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the[ Java Security Standard Algorithm Names Specification](../../../../specs/security/standard-names.html#exemption-mechanisms) for information about standard exemption mechanism names.
`provider` \- the provider.
Returns:
the new `ExemptionMechanism` object
Throws:
`[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if the `provider` is null
`[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")` \- if an `ExemptionMechanismSpi` implementation for the specified algorithm is not available from the specified `Provider object`
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if `algorithm` is `null`
See Also:
[Provider](../../java/security/Provider.html "class in java.security")
* #### getProvider
public final [Provider](../../java/security/Provider.html "class in java.security") getProvider()
Returns the provider of this `ExemptionMechanism` object.
Returns:
the provider of this `ExemptionMechanism` object.
* #### isCryptoAllowed
public final boolean isCryptoAllowed([Key](../../java/security/Key.html "interface in java.security") key)
throws [ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")
Returns whether the result blob has been generated successfully by this exemption mechanism.
The method also makes sure that the key passed in is the same as the one this exemption mechanism used in initializing and generating phases.
Parameters:
`key` \- the key the crypto is going to use.
Returns:
whether the result blob of the same key has been generated successfully by this exemption mechanism; false if `key` is null.
Throws:
`[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")` \- if problem(s) encountered while determining whether the result blob has been generated successfully by this exemption mechanism object.
* #### getOutputSize
public final int getOutputSize(int inputLen)
throws [IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang")
Returns the length in bytes that an output buffer would need to be in order to hold the result of the next[genExemptionBlob](#genExemptionBlob%28byte%5B%5D%29) operation, given the input length `inputLen` (in bytes).
The actual output length of the next[genExemptionBlob](#genExemptionBlob%28byte%5B%5D%29) call may be smaller than the length returned by this method.
Parameters:
`inputLen` \- the input length (in bytes)
Returns:
the required output buffer size (in bytes)
Throws:
`[IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang")` \- if this exemption mechanism is in a wrong state (e.g., has not yet been initialized)
* #### init
public final void init([Key](../../java/security/Key.html "interface in java.security") key)
throws [InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security"),
[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")
Initializes this exemption mechanism with a key.
If this exemption mechanism requires any algorithm parameters that cannot be derived from the given `key`, the underlying exemption mechanism implementation is supposed to generate the required parameters itself (using provider-specific default values); in the case that algorithm parameters must be specified by the caller, an `InvalidKeyException` is raised.
Parameters:
`key` \- the key for this exemption mechanism
Throws:
`[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")` \- if the given key is inappropriate for this exemption mechanism.
`[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")` \- if problem(s) encountered in the process of initializing.
* #### init
public final void init([Key](../../java/security/Key.html "interface in java.security") key,
[AlgorithmParameterSpec](../../java/security/spec/AlgorithmParameterSpec.html "interface in java.security.spec") params)
throws [InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security"),
[InvalidAlgorithmParameterException](../../java/security/InvalidAlgorithmParameterException.html "class in java.security"),
[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")
Initializes this exemption mechanism with a key and a set of algorithm parameters.
If this exemption mechanism requires any algorithm parameters and `params` is null, the underlying exemption mechanism implementation is supposed to generate the required parameters itself (using provider-specific default values); in the case that algorithm parameters must be specified by the caller, an`InvalidAlgorithmParameterException` is raised.
Parameters:
`key` \- the key for this exemption mechanism
`params` \- the algorithm parameters
Throws:
`[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")` \- if the given key is inappropriate for this exemption mechanism.
`[InvalidAlgorithmParameterException](../../java/security/InvalidAlgorithmParameterException.html "class in java.security")` \- if the given algorithm parameters are inappropriate for this exemption mechanism.
`[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")` \- if problem(s) encountered in the process of initializing.
* #### init
public final void init([Key](../../java/security/Key.html "interface in java.security") key,
[AlgorithmParameters](../../java/security/AlgorithmParameters.html "class in java.security") params)
throws [InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security"),
[InvalidAlgorithmParameterException](../../java/security/InvalidAlgorithmParameterException.html "class in java.security"),
[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")
Initializes this exemption mechanism with a key and a set of algorithm parameters.
If this exemption mechanism requires any algorithm parameters and `params` is null, the underlying exemption mechanism implementation is supposed to generate the required parameters itself (using provider-specific default values); in the case that algorithm parameters must be specified by the caller, an`InvalidAlgorithmParameterException` is raised.
Parameters:
`key` \- the key for this exemption mechanism
`params` \- the algorithm parameters
Throws:
`[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")` \- if the given key is inappropriate for this exemption mechanism.
`[InvalidAlgorithmParameterException](../../java/security/InvalidAlgorithmParameterException.html "class in java.security")` \- if the given algorithm parameters are inappropriate for this exemption mechanism.
`[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")` \- if problem(s) encountered in the process of initializing.
* #### genExemptionBlob
public final byte[] genExemptionBlob()
throws [IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang"),
[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")
Generates the exemption mechanism key blob.
Returns:
the new buffer with the result key blob.
Throws:
`[IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang")` \- if this exemption mechanism is in a wrong state (e.g., has not been initialized).
`[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")` \- if problem(s) encountered in the process of generating.
* #### genExemptionBlob
public final int genExemptionBlob(byte[] output)
throws [IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang"),
[ShortBufferException](ShortBufferException.html "class in javax.crypto"),
[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")
Generates the exemption mechanism key blob, and stores the result in the `output` buffer.
If the `output` buffer is too small to hold the result, a `ShortBufferException` is thrown. In this case, repeat this call with a larger output buffer. Use[getOutputSize](#getOutputSize%28int%29) to determine how big the output buffer should be.
Parameters:
`output` \- the buffer for the result
Returns:
the number of bytes stored in `output`
Throws:
`[IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang")` \- if this exemption mechanism is in a wrong state (e.g., has not been initialized).
`[ShortBufferException](ShortBufferException.html "class in javax.crypto")` \- if the given output buffer is too small to hold the result.
`[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")` \- if problem(s) encountered in the process of generating.
* #### genExemptionBlob
public final int genExemptionBlob(byte[] output,
int outputOffset)
throws [IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang"),
[ShortBufferException](ShortBufferException.html "class in javax.crypto"),
[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")
Generates the exemption mechanism key blob, and stores the result in the `output` buffer, starting at `outputOffset` inclusive.
If the `output` buffer is too small to hold the result, a `ShortBufferException` is thrown. In this case, repeat this call with a larger output buffer. Use[getOutputSize](#getOutputSize%28int%29) to determine how big the output buffer should be.
Parameters:
`output` \- the buffer for the result
`outputOffset` \- the offset in `output` where the result is stored
Returns:
the number of bytes stored in `output`
Throws:
`[IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang")` \- if this exemption mechanism is in a wrong state (e.g., has not been initialized).
`[ShortBufferException](ShortBufferException.html "class in javax.crypto")` \- if the given output buffer is too small to hold the result.
`[ExemptionMechanismException](ExemptionMechanismException.html "class in javax.crypto")` \- if problem(s) encountered in the process of generating.