Package javax.crypto
Class ExemptionMechanism
java.lang.Object
javax.crypto.ExemptionMechanism
public class ExemptionMechanism extends Object
This class implements the functionality of an exemption mechanism such as
key recovery, key weakening, or key escrow.
-
Constructor Summary
Constructors Modifier Constructor Description protectedExemptionMechanism(ExemptionMechanismSpi exmechSpi, Provider provider, String mechanism)Creates aExemptionMechanisminstance. -
Method Summary
Modifier and Type Method Description protected voidfinalize()Override to clear any key state in the instance.byte[]genExemptionBlob()Generates the result key blob for this exemption mechanism.intgenExemptionBlob(byte[] output)Generates the result key blob for this exemption mechanism and stores it into theoutputbuffer.intgenExemptionBlob(byte[] output, int outputOffset)Generates the result key blob for this exemption mechanism and stores it into theoutputbuffer at offsetoutputOffset.static ExemptionMechanismgetInstance(String algorithm)Returns a newExemptionMechanisminstance that provides the specified exemption mechanism algorithm.static ExemptionMechanismgetInstance(String algorithm, String provider)Returns a newExemptionMechansminstance that provides the specified exemption mechanism algorithm from the specified provider.static ExemptionMechanismgetInstance(String algorithm, Provider provider)Returns a newExemptionMechanisminstance that provides the specified exemption mechanism algorithm from the specified provider.StringgetName()Returns the name of thisExemptionMechanism.intgetOutputSize(int inputLen)Returns the size in bytes for the output buffer needed to hold the output of the nextgenExemptionBlob()call, given the specifiedinputLen(in bytes).ProvidergetProvider()Returns the provider of thisExemptionMechanisminstance.voidinit(Key key)Initializes thisExemptionMechanisminstance with the specified key.voidinit(Key key, AlgorithmParameters param)Initializes thisExemptionMechanisminstance with the specified key and algorithm parameters.voidinit(Key key, AlgorithmParameterSpec param)Initializes thisExemptionMechanisminstance with the specified key and algorithm parameters.booleanisCryptoAllowed(Key key)Returns whether the result blob for thisExemptionMechanisminstance has been generated successfully and that the specified key is the same as the one that was used to initialize and generate.
-
Constructor Details
-
ExemptionMechanism
Creates aExemptionMechanisminstance.- Parameters:
exmechSpi- the implementation delegate.provider- the associated provider.mechanism- the name of the mechanism.
-
-
Method Details
-
getName
Returns the name of thisExemptionMechanism.- Returns:
- the name of this
ExemptionMechanism.
-
getInstance
public static final ExemptionMechanism getInstance(String algorithm) throws NoSuchAlgorithmExceptionReturns a newExemptionMechanisminstance that provides the specified exemption mechanism algorithm.- Parameters:
algorithm- the name of the requested exemption mechanism.- Returns:
- the new
ExemptionMechanisminstance. - Throws:
NoSuchAlgorithmException- if the specified algorithm is not available by any provider.NullPointerException- if the algorithm parameter isnull.
-
getInstance
public static final ExemptionMechanism getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderExceptionReturns a newExemptionMechansminstance that provides the specified exemption mechanism algorithm from the specified provider.- Parameters:
algorithm- the name of the requested exemption mechanism.provider- the name of the provider that is providing the algorithm.- Returns:
- the new
ExemptionMechanisminstance. - Throws:
NoSuchAlgorithmException- if the specified algorithm is not provided by the specified provider.NoSuchProviderException- if the specified provider is not available.NullPointerException- if the algorithm parameter isnull.IllegalArgumentException- if the provider parameter isnull.
-
getInstance
public static final ExemptionMechanism getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmExceptionReturns a newExemptionMechanisminstance that provides the specified exemption mechanism algorithm from the specified provider.- Parameters:
algorithm- the name of the requested exemption mechanism.provider- the provider that is providing the algorithm.- Returns:
- the new
ExemptionMechanisminstance. - Throws:
NoSuchAlgorithmException- if the specified algorithm is not provided by the specified provider.NullPointerException- if the algorithm parameter isnull.IllegalArgumentException- if the provider parameter isnull.
-
getProvider
Returns the provider of thisExemptionMechanisminstance.- Returns:
- the provider of this
ExemptionMechanisminstance.
-
isCryptoAllowed
Returns whether the result blob for thisExemptionMechanisminstance has been generated successfully and that the specified key is the same as the one that was used to initialize and generate.- Parameters:
key- the key to verify.- Returns:
- whether the result blob for this
ExemptionMechanisminstance has been generated successfully. - Throws:
ExemptionMechanismException- if an error occurs while determining whether the result blob has been generated successfully.
-
getOutputSize
Returns the size in bytes for the output buffer needed to hold the output of the nextgenExemptionBlob()call, given the specifiedinputLen(in bytes).- Parameters:
inputLen- the specified input length (in bytes).- Returns:
- the size in bytes for the output buffer.
- Throws:
IllegalStateException- if thisExemptionMechanisminstance is not initialized.
-
init
Initializes thisExemptionMechanisminstance with the specified key.- Parameters:
key- the key to initialize this instance with.- Throws:
InvalidKeyException- if the key cannot be used to initialize this mechanism.ExemptionMechanismException- if error(s) occur during initialization.
-
init
public final void init(Key key, AlgorithmParameters param) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismExceptionInitializes thisExemptionMechanisminstance with the specified key and algorithm parameters.- Parameters:
key- the key to initialize this instance with.param- the parameters for this exemption mechanism algorithm.- Throws:
InvalidKeyException- if the key cannot be used to initialize this mechanism.InvalidAlgorithmParameterException- if the parameters cannot be used to initialize this mechanism.ExemptionMechanismException- if error(s) occur during initialization.
-
init
public final void init(Key key, AlgorithmParameterSpec param) throws InvalidKeyException, InvalidAlgorithmParameterException, ExemptionMechanismExceptionInitializes thisExemptionMechanisminstance with the specified key and algorithm parameters.- Parameters:
key- the key to initialize this instance with.param- the parameters for this exemption mechanism algorithm.- Throws:
InvalidKeyException- if the key cannot be used to initialize this mechanism.InvalidAlgorithmParameterException- the the parameters cannot be used to initialize this mechanism.ExemptionMechanismException- if error(s) occur during initialization.
-
genExemptionBlob
Generates the result key blob for this exemption mechanism.- Returns:
- the result key blob for this exemption mechanism.
- Throws:
IllegalStateException- if thisExemptionMechanisminstance is not initialized.ExemptionMechanismException- if error(s) occur during generation.
-
genExemptionBlob
public final int genExemptionBlob(byte[] output) throws IllegalStateException, ShortBufferException, ExemptionMechanismExceptionGenerates the result key blob for this exemption mechanism and stores it into theoutputbuffer.- Parameters:
output- the output buffer for the result key blob.- Returns:
- the number of bytes written to the
outputbuffer. - Throws:
IllegalStateException- if thisExemptionMechanisminstance is not initialized.ShortBufferException- if the provided buffer is too small for the result key blob.ExemptionMechanismException- if error(s) occur during generation.
-
genExemptionBlob
public final int genExemptionBlob(byte[] output, int outputOffset) throws IllegalStateException, ShortBufferException, ExemptionMechanismExceptionGenerates the result key blob for this exemption mechanism and stores it into theoutputbuffer at offsetoutputOffset.- Parameters:
output- the output buffer for the result key blob.outputOffset- the offset in the output buffer to start.- Returns:
- the number of bytes written to the
outputbuffer. - Throws:
IllegalStateException- if thisExemptionMechanisminstance is not initialized.ShortBufferException- if the provided buffer is too small for the result key blob.ExemptionMechanismException- if error(s) occur during generation.
-
finalize
protected void finalize()Override to clear any key state in the instance.
-