APIdia Launch Partner
Top Description Fields Constructors Methods
javax.crypto

public Class ExemptionMechanism

extends Object
Class Inheritance
Imports
java.security.AlgorithmParameters, .Provider, .Key, .Security, .NoSuchAlgorithmException, .NoSuchProviderException, .InvalidKeyException, .InvalidAlgorithmParameterException, java.security.spec.AlgorithmParameterSpec, java.util.Objects, sun.security.jca.GetInstance.Instance

This class provides the functionality of an exemption mechanism, examples of which are key recovery, key weakening, and key escrow.

Applications that use an exemption mechanism may be granted stronger encryption capabilities than those which don't.

Since
1.4

Field Summary

Modifier and TypeField and Description
private boolean
private final ExemptionMechanismSpi
private boolean
private Key
private final String
private final Provider

Constructor Summary

AccessConstructor and Description
protected
ExemptionMechanism(ExemptionMechanismSpi
the delegate
exmechSpi
,
Provider
the provider
provider
,
String
the exemption mechanism
mechanism
)

Creates an ExemptionMechanism object.

Method Summary

Modifier and TypeMethod and Description
public final byte[]

Returns:

the new buffer with the result key blob.
genExemptionBlob
()

Generates the exemption mechanism key blob.

public final int

Returns:

the number of bytes stored in output
genExemptionBlob
(byte[]
the buffer for the result
output
)

Generates the exemption mechanism key blob, and stores the result in the output buffer.

public final int

Returns:

the number of bytes stored in output
genExemptionBlob
(byte[]
the buffer for the result
output
,
int
the offset in output where the result is stored
outputOffset
)

Generates the exemption mechanism key blob, and stores the result in the output buffer, starting at outputOffset inclusive.

public static final ExemptionMechanism

Returns:

the new ExemptionMechanism object
getInstance
(String
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.
algorithm
)

Returns an ExemptionMechanism object that implements the specified exemption mechanism algorithm.

public static final ExemptionMechanism

Returns:

the new ExemptionMechanism object
getInstance
(String
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.
algorithm
,
String
the name of the provider.
provider
)

Returns an ExemptionMechanism object that implements the specified exemption mechanism algorithm.

public static final ExemptionMechanism

Returns:

the new ExemptionMechanism object
getInstance
(String
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.
algorithm
,
Provider
the provider.
provider
)

Returns an ExemptionMechanism object that implements the specified exemption mechanism algorithm.

public final String

Returns:

the exemption mechanism name of this ExemptionMechanism object.
getName
()

Returns the exemption mechanism name of this ExemptionMechanism object.

public final int

Returns:

the required output buffer size (in bytes)
getOutputSize
(int
the input length (in bytes)
inputLen
)

Returns the length in bytes that an output buffer would need to be in order to hold the result of the next genExemptionBlob operation, given the input length inputLen (in bytes).

public final Provider

Returns:

the provider of this ExemptionMechanism object.
getProvider
()

Returns the provider of this ExemptionMechanism object.

public final void
init(Key
the key for this exemption mechanism
key
)

Initializes this exemption mechanism with a key.

public final void
init(Key
the key for this exemption mechanism
key
,
AlgorithmParameterSpec
the algorithm parameters
params
)

Initializes this exemption mechanism with a key and a set of algorithm parameters.

public final void
init(Key
the key for this exemption mechanism
key
,
AlgorithmParameters
the algorithm parameters
params
)

Initializes this exemption mechanism with a key and a set of algorithm parameters.

public final boolean

Returns:

whether the result blob of the same key has been generated successfully by this exemption mechanism; false if key is null.
isCryptoAllowed
(Key
the key the crypto is going to use.
key
)

Returns whether the result blob has been generated successfully by this exemption mechanism.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

doneback to summary
private boolean done
exmechSpiback to summary
private final ExemptionMechanismSpi exmechSpi
initializedback to summary
private boolean initialized
keyStoredback to summary
private Key keyStored
mechanismback to summary
private final String mechanism
providerback to summary
private final Provider provider

Constructor Detail

ExemptionMechanismback to summary
protected ExemptionMechanism(ExemptionMechanismSpi exmechSpi, Provider provider, String mechanism)

Creates an ExemptionMechanism object.

Parameters
exmechSpi:ExemptionMechanismSpi

the delegate

provider:Provider

the provider

mechanism:String

the exemption mechanism

Method Detail

genExemptionBlobback to summary
public final byte[] genExemptionBlob() throws IllegalStateException, ExemptionMechanismException

Generates the exemption mechanism key blob.

Returns:byte[]

the new buffer with the result key blob.

Exceptions
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.
genExemptionBlobback to summary
public final int genExemptionBlob(byte[] output) throws IllegalStateException, ShortBufferException, ExemptionMechanismException

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 to determine how big the output buffer should be.

Parameters
output:byte[]

the buffer for the result

Returns:int

the number of bytes stored in output

Exceptions
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.
genExemptionBlobback to summary
public final int genExemptionBlob(byte[] output, int outputOffset) throws IllegalStateException, ShortBufferException, ExemptionMechanismException

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 to determine how big the output buffer should be.

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

Exceptions
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.
getInstanceback to summary
public static final ExemptionMechanism getInstance(String algorithm) throws NoSuchAlgorithmException

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() 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 by Security.getProviders().

Parameters
algorithm:String

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:ExemptionMechanism

the new ExemptionMechanism object

Exceptions
NoSuchAlgorithmException:
if no Provider supports an ExemptionMechanismSpi implementation for the specified algorithm
NullPointerException:
if algorithm is null
External Specification
Java Security Standard Algorithm Names
See Also
java.security.Provider
getInstanceback to summary
public static final ExemptionMechanism getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException

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() method.

Parameters
algorithm:String

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:String

the name of the provider.

Returns:ExemptionMechanism

the new ExemptionMechanism object

Exceptions
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
NullPointerException:
if algorithm is null
External Specification
Java Security Standard Algorithm Names
See Also
java.security.Provider
getInstanceback to summary
public static final ExemptionMechanism getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException

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:String

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:Provider

the provider.

Returns:ExemptionMechanism

the new ExemptionMechanism object

Exceptions
NoSuchAlgorithmException:
if an ExemptionMechanismSpi implementation for the specified algorithm is not available from the specified Provider object
IllegalArgumentException:
if the provider is null
NullPointerException:
if algorithm is null
External Specification
Java Security Standard Algorithm Names
See Also
java.security.Provider
getNameback to summary
public final String 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:String

the exemption mechanism name of this ExemptionMechanism object.

getOutputSizeback to summary
public final int getOutputSize(int inputLen) throws IllegalStateException

Returns the length in bytes that an output buffer would need to be in order to hold the result of the next genExemptionBlob operation, given the input length inputLen (in bytes).

The actual output length of the next genExemptionBlob call may be smaller than the length returned by this method.

Parameters
inputLen:int

the input length (in bytes)

Returns:int

the required output buffer size (in bytes)

Exceptions
IllegalStateException:
if this exemption mechanism is in a wrong state (e.g., has not yet been initialized)
getProviderback to summary
public final Provider getProvider()

Returns the provider of this ExemptionMechanism object.

Returns:Provider

the provider of this ExemptionMechanism object.

initback to summary
public final void init(Key key) throws InvalidKeyException, ExemptionMechanismException

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:Key

the key for this exemption mechanism

Exceptions
InvalidKeyException:
if the given key is inappropriate for this exemption mechanism.
ExemptionMechanismException:
if problem(s) encountered in the process of initializing.
initback to summary
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 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:Key

the key for this exemption mechanism

params:AlgorithmParameterSpec

the algorithm parameters

Exceptions
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.
initback to summary
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 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:Key

the key for this exemption mechanism

params:AlgorithmParameters

the algorithm parameters

Exceptions
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.
isCryptoAllowedback to summary
public final boolean isCryptoAllowed(Key key) throws ExemptionMechanismException

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: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.

Exceptions
ExemptionMechanismException:
if problem(s) encountered while determining whether the result blob has been generated successfully by this exemption mechanism object.