Class ExemptionMechanism
Applications that use an exemption mechanism may be granted stronger encryption capabilities than those which don't.
- Since:
- 1.4
-
Constructor Summary
ModifierConstructorDescriptionprotected
ExemptionMechanism
(ExemptionMechanismSpi exmechSpi, Provider provider, String mechanism) Creates anExemptionMechanism
object. -
Method Summary
Modifier and TypeMethodDescriptionfinal byte[]
Generates the exemption mechanism key blob.final int
genExemptionBlob
(byte[] output) Generates the exemption mechanism key blob, and stores the result in theoutput
buffer.final int
genExemptionBlob
(byte[] output, int outputOffset) Generates the exemption mechanism key blob, and stores the result in theoutput
buffer, starting atoutputOffset
inclusive.static final ExemptionMechanism
getInstance
(String algorithm) Returns anExemptionMechanism
object that implements the specified exemption mechanism algorithm.static final ExemptionMechanism
getInstance
(String algorithm, String provider) Returns anExemptionMechanism
object that implements the specified exemption mechanism algorithm.static final ExemptionMechanism
getInstance
(String algorithm, Provider provider) Returns anExemptionMechanism
object that implements the specified exemption mechanism algorithm.final String
getName()
Returns the exemption mechanism name of thisExemptionMechanism
object.final int
getOutputSize
(int inputLen) Returns the length in bytes that an output buffer would need to be in order to hold the result of the nextgenExemptionBlob
operation, given the input lengthinputLen
(in bytes).final Provider
Returns the provider of thisExemptionMechanism
object.final void
Initializes this exemption mechanism with a key.final void
init
(Key key, AlgorithmParameters params) Initializes this exemption mechanism with a key and a set of algorithm parameters.final void
init
(Key key, AlgorithmParameterSpec params) Initializes this exemption mechanism with a key and a set of algorithm parameters.final boolean
isCryptoAllowed
(Key key) Returns whether the result blob has been generated successfully by this exemption mechanism.
-
Constructor Details
-
ExemptionMechanism
Creates anExemptionMechanism
object.- Parameters:
exmechSpi
- the delegateprovider
- the providermechanism
- the exemption mechanism
-
-
Method Details
-
getName
Returns the exemption mechanism name of thisExemptionMechanism
object.This is the same name that was specified in one of the
getInstance
calls that created thisExemptionMechanism
object.- Returns:
- the exemption mechanism name of this
ExemptionMechanism
object.
-
getInstance
public static final ExemptionMechanism getInstance(String algorithm) throws NoSuchAlgorithmException Returns anExemptionMechanism
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 theExemptionMechanismSpi
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()
method.- Implementation Note:
- The JDK Reference Implementation additionally uses the
jdk.security.provider.preferred
Security
property to determine the preferred provider order for the specified algorithm. This may be different from the order of providers returned bySecurity.getProviders()
. - Parameters:
algorithm
- the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the Java Security Standard Algorithm Names Specification for information about standard exemption mechanism names.- Returns:
- the new
ExemptionMechanism
object - Throws:
NoSuchAlgorithmException
- if noProvider
supports anExemptionMechanismSpi
implementation for the specified algorithmNullPointerException
- ifalgorithm
isnull
- See Also:
-
getInstance
public static final ExemptionMechanism getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException Returns anExemptionMechanism
object that implements the specified exemption mechanism algorithm.A new
ExemptionMechanism
object encapsulating theExemptionMechanismSpi
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()
method.- Parameters:
algorithm
- the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the Java Security Standard Algorithm Names Specification for information about standard exemption mechanism names.provider
- the name of the provider.- Returns:
- the new
ExemptionMechanism
object - Throws:
IllegalArgumentException
- if theprovider
isnull
or emptyNoSuchAlgorithmException
- if anExemptionMechanismSpi
implementation for the specified algorithm is not available from the specified providerNoSuchProviderException
- if the specified provider is not registered in the security provider listNullPointerException
- ifalgorithm
isnull
- See Also:
-
getInstance
public static final ExemptionMechanism getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException Returns anExemptionMechanism
object that implements the specified exemption mechanism algorithm.A new
ExemptionMechanism
object encapsulating theExemptionMechanismSpi
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 for information about standard exemption mechanism names.provider
- the provider.- Returns:
- the new
ExemptionMechanism
object - Throws:
IllegalArgumentException
- if theprovider
isnull
NoSuchAlgorithmException
- if anExemptionMechanismSpi
implementation for the specified algorithm is not available from the specifiedProvider
objectNullPointerException
- ifalgorithm
isnull
- See Also:
-
getProvider
Returns the provider of thisExemptionMechanism
object.- Returns:
- the provider of this
ExemptionMechanism
object.
-
isCryptoAllowed
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
ifkey
isnull
. - Throws:
ExemptionMechanismException
- if problem(s) encountered while determining whether the result blob has been generated successfully by this exemption mechanism object.
-
getOutputSize
Returns the length in bytes that an output buffer would need to be in order to hold the result of the nextgenExemptionBlob
operation, given the input lengthinputLen
(in bytes).The actual output length of the next
genExemptionBlob
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
- if this exemption mechanism is in a wrong state (e.g., has not yet been initialized)
-
init
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, anInvalidKeyException
is raised.- Parameters:
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.
-
init
public final void init(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismException Initializes this exemption mechanism with a key and a set of algorithm parameters.If this exemption mechanism requires any algorithm parameters and
params
isnull
, 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, anInvalidAlgorithmParameterException
is raised.- Parameters:
key
- the key for this exemption mechanismparams
- 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
public final void init(Key key, AlgorithmParameters params) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismException Initializes this exemption mechanism with a key and a set of algorithm parameters.If this exemption mechanism requires any algorithm parameters and
params
isnull
, 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, anInvalidAlgorithmParameterException
is raised.- Parameters:
key
- the key for this exemption mechanismparams
- 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.
-
genExemptionBlob
Generates the exemption mechanism key blob.- Returns:
- 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
public final int genExemptionBlob(byte[] output) throws IllegalStateException, ShortBufferException, ExemptionMechanismException Generates the exemption mechanism key blob, and stores the result in theoutput
buffer.If the
output
buffer is too small to hold the result, aShortBufferException
is thrown. In this case, repeat this call with a larger output buffer. UsegetOutputSize
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
- 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
public final int genExemptionBlob(byte[] output, int outputOffset) throws IllegalStateException, ShortBufferException, ExemptionMechanismException Generates the exemption mechanism key blob, and stores the result in theoutput
buffer, starting atoutputOffset
inclusive.If the
output
buffer is too small to hold the result, aShortBufferException
is thrown. In this case, repeat this call with a larger output buffer. UsegetOutputSize
to determine how big the output buffer should be.- Parameters:
output
- the buffer for the resultoutputOffset
- the offset inoutput
where the result is stored- Returns:
- 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.
-