Class ExemptionMechanism
- java.lang.Object
-
- javax.crypto.ExemptionMechanism
-
public class ExemptionMechanism extends java.lang.ObjectThis 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.
- Since:
- 1.4
-
-
Constructor Summary
Constructors Modifier Constructor and Description protectedExemptionMechanism(ExemptionMechanismSpi exmechSpi, java.security.Provider provider, java.lang.String mechanism)Creates a ExemptionMechanism object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description protected voidfinalize()Ensures that the key stored away by this ExemptionMechanism object will be wiped out when there are no more references to it.byte[]genExemptionBlob()Generates the exemption mechanism key blob.intgenExemptionBlob(byte[] output)Generates the exemption mechanism key blob, and stores the result in theoutputbuffer.intgenExemptionBlob(byte[] output, int outputOffset)Generates the exemption mechanism key blob, and stores the result in theoutputbuffer, starting atoutputOffsetinclusive.static ExemptionMechanismgetInstance(java.lang.String algorithm)Returns anExemptionMechanismobject that implements the specified exemption mechanism algorithm.static ExemptionMechanismgetInstance(java.lang.String algorithm, java.security.Provider provider)Returns anExemptionMechanismobject that implements the specified exemption mechanism algorithm.static ExemptionMechanismgetInstance(java.lang.String algorithm, java.lang.String provider)Returns anExemptionMechanismobject that implements the specified exemption mechanism algorithm.java.lang.StringgetName()Returns the exemption mechanism name of thisExemptionMechanismobject.intgetOutputSize(int inputLen)Returns the length in bytes that an output buffer would need to be in order to hold the result of the nextgenExemptionBloboperation, given the input lengthinputLen(in bytes).java.security.ProvidergetProvider()Returns the provider of thisExemptionMechanismobject.voidinit(java.security.Key key)Initializes this exemption mechanism with a key.voidinit(java.security.Key key, java.security.AlgorithmParameters params)Initializes this exemption mechanism with a key and a set of algorithm parameters.voidinit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)Initializes this exemption mechanism with a key and a set of algorithm parameters.booleanisCryptoAllowed(java.security.Key key)Returns whether the result blob has been generated successfully by this exemption mechanism.
-
-
-
Constructor Detail
-
ExemptionMechanism
protected ExemptionMechanism(ExemptionMechanismSpi exmechSpi, java.security.Provider provider, java.lang.String mechanism)
Creates a ExemptionMechanism object.- Parameters:
exmechSpi- the delegateprovider- the providermechanism- the exemption mechanism
-
-
Method Detail
-
getName
public final java.lang.String getName()
Returns the exemption mechanism name of thisExemptionMechanismobject.This is the same name that was specified in one of the
getInstancecalls that created thisExemptionMechanismobject.- Returns:
- the exemption mechanism name of this
ExemptionMechanismobject.
-
getInstance
public static final ExemptionMechanism getInstance(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
Returns anExemptionMechanismobject 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.- Parameters:
algorithm- the standard name of the requested exemption mechanism. See Appendix A in the Java Cryptography Extension Reference Guide for information about standard exemption mechanism names.- Returns:
- the new
ExemptionMechanismobject. - Throws:
java.lang.NullPointerException- ifalgorithmis null.java.security.NoSuchAlgorithmException- if no Provider supports an ExemptionMechanismSpi implementation for the specified algorithm.- See Also:
Provider
-
getInstance
public static final ExemptionMechanism getInstance(java.lang.String algorithm, java.lang.String provider) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException
Returns anExemptionMechanismobject 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- the standard name of the requested exemption mechanism. See Appendix A in the Java Cryptography Extension Reference Guide for information about standard exemption mechanism names.provider- the name of the provider- Returns:
- the new
ExemptionMechanismobject. - Throws:
java.lang.NullPointerException- ifalgorithmis null.java.security.NoSuchAlgorithmException- if an ExemptionMechanismSpi implementation for the specified algorithm is not available from the specified provider.java.security.NoSuchProviderException- if the specified provider is not registered in the security provider list.java.lang.IllegalArgumentException- if theprovideris null or empty.- See Also:
Provider
-
getInstance
public static final ExemptionMechanism getInstance(java.lang.String algorithm, java.security.Provider provider) throws java.security.NoSuchAlgorithmException
Returns anExemptionMechanismobject 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 Appendix A in the Java Cryptography Extension Reference Guide for information about standard exemption mechanism names.provider- the provider.- Returns:
- the new
ExemptionMechanismobject. - Throws:
java.lang.NullPointerException- ifalgorithmis null.java.security.NoSuchAlgorithmException- if an ExemptionMechanismSpi implementation for the specified algorithm is not available from the specified Provider object.java.lang.IllegalArgumentException- if theprovideris null.- See Also:
Provider
-
getProvider
public final java.security.Provider getProvider()
Returns the provider of thisExemptionMechanismobject.- Returns:
- the provider of this
ExemptionMechanismobject.
-
isCryptoAllowed
public final boolean isCryptoAllowed(java.security.Key key) throws ExemptionMechanismExceptionReturns 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
keyis null. - Throws:
ExemptionMechanismException- 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 java.lang.IllegalStateExceptionReturns the length in bytes that an output buffer would need to be in order to hold the result of the nextgenExemptionBloboperation, given the input lengthinputLen(in bytes).The actual output length of the next
genExemptionBlobcall 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:
java.lang.IllegalStateException- if this exemption mechanism is in a wrong state (e.g., has not yet been initialized)
-
init
public final void init(java.security.Key key) throws java.security.InvalidKeyException, ExemptionMechanismExceptionInitializes 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, anInvalidKeyExceptionis raised.- Parameters:
key- the key for this exemption mechanism- Throws:
java.security.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(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException, ExemptionMechanismExceptionInitializes this exemption mechanism with a key and a set of algorithm parameters.If this exemption mechanism requires any algorithm parameters and
paramsis 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, anInvalidAlgorithmParameterExceptionis raised.- Parameters:
key- the key for this exemption mechanismparams- the algorithm parameters- Throws:
java.security.InvalidKeyException- if the given key is inappropriate for this exemption mechanism.java.security.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(java.security.Key key, java.security.AlgorithmParameters params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException, ExemptionMechanismExceptionInitializes this exemption mechanism with a key and a set of algorithm parameters.If this exemption mechanism requires any algorithm parameters and
paramsis 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, anInvalidAlgorithmParameterExceptionis raised.- Parameters:
key- the key for this exemption mechanismparams- the algorithm parameters- Throws:
java.security.InvalidKeyException- if the given key is inappropriate for this exemption mechanism.java.security.InvalidAlgorithmParameterException- if the given algorithm parameters are inappropriate for this exemption mechanism.ExemptionMechanismException- if problem(s) encountered in the process of initializing.
-
genExemptionBlob
public final byte[] genExemptionBlob() throws java.lang.IllegalStateException, ExemptionMechanismExceptionGenerates the exemption mechanism key blob.- Returns:
- the new buffer with the result key blob.
- Throws:
java.lang.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 java.lang.IllegalStateException, ShortBufferException, ExemptionMechanismExceptionGenerates the exemption mechanism key blob, and stores the result in theoutputbuffer.If the
outputbuffer is too small to hold the result, aShortBufferExceptionis thrown. In this case, repeat this call with a larger output buffer. UsegetOutputSizeto determine how big the output buffer should be.- Parameters:
output- the buffer for the result- Returns:
- the number of bytes stored in
output - Throws:
java.lang.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 java.lang.IllegalStateException, ShortBufferException, ExemptionMechanismExceptionGenerates the exemption mechanism key blob, and stores the result in theoutputbuffer, starting atoutputOffsetinclusive.If the
outputbuffer is too small to hold the result, aShortBufferExceptionis thrown. In this case, repeat this call with a larger output buffer. UsegetOutputSizeto determine how big the output buffer should be.- Parameters:
output- the buffer for the resultoutputOffset- the offset inoutputwhere the result is stored- Returns:
- the number of bytes stored in
output - Throws:
java.lang.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.
-
finalize
protected void finalize()
Ensures that the key stored away by this ExemptionMechanism object will be wiped out when there are no more references to it.- Overrides:
finalizein classjava.lang.Object
-
-