# ExemptionMechanism

public class **ExemptionMechanism** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
This class provides the functionality of an exemption mechanism, examples
of which are *key recovery*, *key weakening*, and
*key escrow*.

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

### Protected Constructor Summary

|---|---|
|   | [ExemptionMechanism](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#ExemptionMechanism(javax.crypto.ExemptionMechanismSpi,%20java.security.Provider,%20java.lang.String))([ExemptionMechanismSpi](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismSpi.html) exmechSpi, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) mechanism) Creates a ExemptionMechanism object. |

### Public Method Summary

|---|---|
| final int | [genExemptionBlob](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#genExemptionBlob(byte[]))(byte\[\] output) Generates the exemption mechanism key blob, and stores the result in the `output` buffer. |
| final byte\[\] | [genExemptionBlob](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#genExemptionBlob())() Generates the exemption mechanism key blob. |
| final int | [genExemptionBlob](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#genExemptionBlob(byte[],%20int))(byte\[\] output, int outputOffset) Generates the exemption mechanism key blob, and stores the result in the `output` buffer, starting at `outputOffset` inclusive. |
| final static [ExemptionMechanism](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#getInstance(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm) Returns an `ExemptionMechanism` object that implements the specified exemption mechanism algorithm. |
| final static [ExemptionMechanism](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#getInstance(java.lang.String,%20java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) provider) Returns an `ExemptionMechanism` object that implements the specified exemption mechanism algorithm. |
| final static [ExemptionMechanism](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#getInstance(java.lang.String,%20java.security.Provider))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider) Returns an `ExemptionMechanism` object that implements the specified exemption mechanism algorithm. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getName](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#getName())() Returns the exemption mechanism name of this `ExemptionMechanism` object. |
| final int | [getOutputSize](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#getOutputSize(int))(int inputLen) Returns the length in bytes that an output buffer would need to be in order to hold the result of the next `https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#genExemptionBlob(byte[])` operation, given the input length `inputLen` (in bytes). |
| final [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) | [getProvider](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#getProvider())() Returns the provider of this `ExemptionMechanism` object. |
| final void | [init](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#init(java.security.Key,%20java.security.AlgorithmParameters))([Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key, [AlgorithmParameters](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AlgorithmParameters.html) params) Initializes this exemption mechanism with a key and a set of algorithm parameters. |
| final void | [init](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#init(java.security.Key,%20java.security.spec.AlgorithmParameterSpec))([Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key, [AlgorithmParameterSpec](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/spec/AlgorithmParameterSpec.html) params) Initializes this exemption mechanism with a key and a set of algorithm parameters. |
| final void | [init](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#init(java.security.Key))([Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key) Initializes this exemption mechanism with a key. |
| final boolean | [isCryptoAllowed](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#isCryptoAllowed(java.security.Key))([Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key) Returns whether the result blob has been generated successfully by this exemption mechanism. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Protected Constructors

#### protected
**ExemptionMechanism**
([ExemptionMechanismSpi](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismSpi.html) exmechSpi, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) mechanism)

Creates a ExemptionMechanism object.

##### Parameters

| exmechSpi | the delegate |
| provider | the provider |
| mechanism | the exemption mechanism |
|---|---|

## Public Methods

#### public final int
**genExemptionBlob**
(byte\[\] output)

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
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#getOutputSize(int)` 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](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | if this exemption mechanism is in a wrong state (e.g., has not been initialized). |
| [ShortBufferException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ShortBufferException.html) | if the given output buffer is too small to hold the result. |
| [ExemptionMechanismException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismException.html) | if problem(s) encountered in the process of generating. |
|---|---|

#### public final byte\[\]
**genExemptionBlob**
()

Generates the exemption mechanism key blob.

##### Returns

- the new buffer with the result key blob.

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | if this exemption mechanism is in a wrong state (e.g., has not been initialized). |
| [ExemptionMechanismException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismException.html) | if problem(s) encountered in the process of generating. |
|---|---|

#### public final int
**genExemptionBlob**
(byte\[\] output, int outputOffset)

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
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#getOutputSize(int)` 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](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | if this exemption mechanism is in a wrong state (e.g., has not been initialized). |
| [ShortBufferException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ShortBufferException.html) | if the given output buffer is too small to hold the result. |
| [ExemptionMechanismException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismException.html) | if problem(s) encountered in the process of generating. |
|---|---|

#### public static final [ExemptionMechanism](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html)
**getInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm)

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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Security.html#getProviders()` method.

##### Parameters

| algorithm | the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the [Java Cryptography Architecture Standard Algorithm Name Documentation](https://developers.google.com/j2objc/javadoc/jre/technotes/guides/security/StandardNames.html#Exemption) for information about standard exemption mechanism names. |
|---|---|

##### Returns

- the new `ExemptionMechanism` object.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `algorithm` is null. |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if no Provider supports an ExemptionMechanismSpi implementation for the specified algorithm. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html`

#### public static final [ExemptionMechanism](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html)
**getInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) provider)

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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Security.html#getProviders()` method.

##### Parameters

| algorithm | the standard name of the requested exemption mechanism. See the ExemptionMechanism section in the [Java Cryptography Architecture Standard Algorithm Name Documentation](https://developers.google.com/j2objc/javadoc/jre/technotes/guides/security/StandardNames.html#Exemption) for information about standard exemption mechanism names. |
| provider | the name of the provider. |
|---|---|

##### Returns

- the new `ExemptionMechanism` object.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `algorithm` is null. |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if an ExemptionMechanismSpi implementation for the specified algorithm is not available from the specified provider. |
| [NoSuchProviderException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchProviderException.html) | if the specified provider is not registered in the security provider list. |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the `provider` is null or empty. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html`

#### public static final [ExemptionMechanism](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html)
**getInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider)

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 Cryptography Architecture Standard Algorithm Name Documentation](https://developers.google.com/j2objc/javadoc/jre/technotes/guides/security/StandardNames.html#Exemption) for information about standard exemption mechanism names. |
| provider | the provider. |
|---|---|

##### Returns

- the new `ExemptionMechanism` object.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `algorithm` is null. |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if an ExemptionMechanismSpi implementation for the specified algorithm is not available from the specified Provider object. |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the `provider` is null. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html`

#### public final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**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.

#### public 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 next
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#genExemptionBlob(byte[])`
operation, given the input length `inputLen` (in bytes).

The actual output length of the next
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanism.html#genExemptionBlob(byte[])`
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](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | if this exemption mechanism is in a wrong state (e.g., has not yet been initialized) |
|---|---|

#### public final [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html)
**getProvider**
()

Returns the provider of this `ExemptionMechanism` object.

##### Returns

- the provider of this `ExemptionMechanism` object.

#### public final void
**init**
([Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key, [AlgorithmParameters](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AlgorithmParameters.html) params)

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](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/InvalidKeyException.html) | if the given key is inappropriate for this exemption mechanism. |
| [InvalidAlgorithmParameterException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/InvalidAlgorithmParameterException.html) | if the given algorithm parameters are inappropriate for this exemption mechanism. |
| [ExemptionMechanismException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismException.html) | if problem(s) encountered in the process of initializing. |
|---|---|

#### public final void
**init**
([Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key, [AlgorithmParameterSpec](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/spec/AlgorithmParameterSpec.html) params)

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](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/InvalidKeyException.html) | if the given key is inappropriate for this exemption mechanism. |
| [InvalidAlgorithmParameterException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/InvalidAlgorithmParameterException.html) | if the given algorithm parameters are inappropriate for this exemption mechanism. |
| [ExemptionMechanismException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismException.html) | if problem(s) encountered in the process of initializing. |
|---|---|

#### public final void
**init**
([Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key)

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](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/InvalidKeyException.html) | if the given key is inappropriate for this exemption mechanism. |
| [ExemptionMechanismException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismException.html) | if problem(s) encountered in the process of initializing. |
|---|---|

#### public final boolean
**isCryptoAllowed**
([Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key)

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](https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/ExemptionMechanismException.html) | if problem(s) encountered while determining whether the result blob has been generated successfully by this exemption mechanism object. |
|---|---|