public abstract class KeyHandler extends Configurable
IAIKPkcs11.setGlobalKeyHandler(KeyHandler)
method.
All cipher, MAC and signature engines of this provider call this method of the current key
handler in their init
methods; e.g. the javax.crypto.Cipher.init(int,Key) method.
This method is called with the original key passed to the init
method. The engine
object will continue processing with the returned key and will not use the original key any
longer.
This allows the key handler to convert the provided key automatically before the PKCS#11 provider starts working with them. For example, a key handler can convert pure software keys of the JCA and JCE framework to PKCS#11 key objects automatically. Such automatic conversion can be especially useful when the PKCS#11 provider is used in conbination with old software or with software which is not aware of any crypto hardware features. This allows simple integration of crpyto accelleration. Please note that this feature will not increase the overall security of the system. The operations are done in the crypto hardware, but the keys still come through the software.
A key handler may decide not to modify the keys and return the provided keys as they are.
DefaultKeyHandler
defaultProperties_, properties_
Constructor and Description |
---|
KeyHandler() |
Modifier and Type | Method and Description |
---|---|
abstract iaik.pkcs.pkcs11.objects.SecretKey |
getKeyGeneratorTemplate(java.lang.String algorithm,
java.security.spec.AlgorithmParameterSpec params)
Get a secret key template object for the given key generation algorithm.
|
abstract iaik.pkcs.pkcs11.objects.SecretKey |
getKeyGeneratorTemplate(java.lang.String algorithm,
int keySize)
Get a secret key template object for the given key generation algorithm.
|
abstract iaik.pkcs.pkcs11.objects.KeyPair |
getKeyPairGeneratorTemplate(java.lang.String algorithm,
java.security.spec.AlgorithmParameterSpec params)
Get a private and a public key template object for the given key-pair generation algorithm.
|
abstract iaik.pkcs.pkcs11.objects.KeyPair |
getKeyPairGeneratorTemplate(java.lang.String algorithm,
int keySize)
Get a private and a public key template object for the given key-pair generation algorithm.
|
abstract java.security.Key |
handleCipherKey(java.lang.String algorithm,
int operationMode,
java.security.Key key)
All cipher engines of this provider call this method of the current key handler in their
init methods; e.g. |
abstract java.security.Key |
handleKeyAgreementKey(java.lang.String algorithm,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Handle the initial key which has been passed to the
init method of a key-agreement
object. |
abstract java.security.Key |
handleKeyAgreementPhaseKey(java.lang.String algorithm,
java.security.Key key)
Handle the a phase key which has been passed to the
doPhase method of a
key-agreement object. |
abstract java.security.spec.KeySpec |
handleKeyFactoryGeneratePrivate(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
Key factories (for private and public keys) of this provider call this method of the current
key handler.
|
abstract java.security.spec.KeySpec |
handleKeyFactoryGeneratePublic(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
Key factories (for private and public keys) of this provider call this method of the current
key handler.
|
abstract java.security.Key |
handleKeyFactoryTranslateKey(java.lang.String algorithm,
java.security.Key key)
Key factories (for private and public keys) of this provider call this method of the current
key handler.
|
abstract java.security.Key |
handleMacKey(java.lang.String algorithm,
java.security.Key key)
All MAC engines of this provider call this method of the current key handler in their
init methods; e.g. |
abstract java.security.spec.KeySpec |
handleSecretKeyFactoryGenerateSecret(java.lang.String algorithm,
java.security.spec.KeySpec keySpec)
Secret key factories of this provider call this method of the current key handler.
|
abstract javax.crypto.SecretKey |
handleSecretKeyFactoryTranslateKey(java.lang.String algorithm,
javax.crypto.SecretKey key)
Secret key factories of this provider call this method of the current key handler.
|
abstract java.security.PrivateKey |
handleSignatureKey(java.lang.String algorithm,
java.security.PrivateKey key)
All signature engines of this provider call this method of the current key handler in their
initSign methods; e.g. |
abstract java.security.PublicKey |
handleVerificationKey(java.lang.String algorithm,
java.security.PublicKey key)
All signature engines of this provider call this method of the current key handler in their
initVerify methods; e.g. |
addProperties, getProperties, propertiesChanged, setProperties
public abstract java.security.Key handleCipherKey(java.lang.String algorithm, int operationMode, java.security.Key key) throws java.security.InvalidKeyException
init
methods; e.g. the javax.crypto.Cipher.init(int,Key)
method. This
method is called with the original key passed to the init
method. The engine
object will continue processing with the returned key and will not use the original key any
longer.algorithm
- The JCE name of the cipher algorithm; e.g. RSA
or DESede
.
Note that this is not the complete transformation string like
DESese/CBC/PKCS5Padding
.operationMode
- The mode as passed to the cipher's init
method; e.g.
Cipher.ENCRYPT_MODE
.key
- The key.java.security.InvalidKeyException
- If the given key is invalid for this algorithm or mode.public abstract java.security.Key handleMacKey(java.lang.String algorithm, java.security.Key key) throws java.security.InvalidKeyException
init
methods; e.g. the javax.crypto.Mac.init(Key)
method. This method
is called with the original key passed to the init
method. The engine object will
continue processing with the returned key and will not use the original key any longer.algorithm
- The JCE name of the MAC algorithm; e.g. HmacSHA1
.key
- The key.java.security.InvalidKeyException
- If the given key is invalid for this algorithm.public abstract java.security.PrivateKey handleSignatureKey(java.lang.String algorithm, java.security.PrivateKey key) throws java.security.InvalidKeyException
initSign
methods; e.g. the
java.security.Signature.initSign(PrivateKey)
method. This method is called with
the original key passed to the initSign
method. The engine object will continue
processing with the returned key and will not use the original key any longer.algorithm
- The JCA name of the signature algorithm; e.g. SHA1withRSA
.key
- The signature key.java.security.InvalidKeyException
- If the given key is invalid for this algorithm or mode.public abstract java.security.PublicKey handleVerificationKey(java.lang.String algorithm, java.security.PublicKey key) throws java.security.InvalidKeyException
initVerify
methods; e.g. the
java.security.Signature.initVerify(PublicKey)
method. This method is called with
the original key passed to the initVerify
method. The engine object will continue
processing with the returned key and will not use the original key any longer.algorithm
- The JCA name of the signature algorithm; e.g. SHA1withRSA
.key
- The verification key.java.security.InvalidKeyException
- If the given key is invalid for this algorithm or mode.public abstract java.security.Key handleKeyAgreementKey(java.lang.String algorithm, java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException
init
method of a key-agreement
object. This is the private key.algorithm
- The JCE name of the key agreement algorithm; e.g. DH
.key
- The private key for key agreement.params
- The algorithm parameters passed to the init
metod of the key agreement
object.java.security.InvalidKeyException
- If the given key is invalid for this algorithm or mode.public abstract java.security.Key handleKeyAgreementPhaseKey(java.lang.String algorithm, java.security.Key key) throws java.security.InvalidKeyException
doPhase
method of a
key-agreement object. This is a public key of a party involved in the key agreement.algorithm
- The JCE name of the key agreement algorithm; e.g. DH
.key
- The public phase key.java.security.InvalidKeyException
- If the given key is invalid for this algorithm or mode.public abstract java.security.spec.KeySpec handleKeyFactoryGeneratePublic(java.lang.String algorithm, java.security.spec.KeySpec keySpec) throws java.security.spec.InvalidKeySpecException
generatePublic(KeySpec)
method implementation. The factory proceeds with the
KeySpec
returned by this method. It does not use the original any longer.
This allows the key handler to translate the given key spec into a
PKCS11KeySpec
for a default provider instance.
algorithm
- The algorithm name of the key factory; e.g. RSA.keySpec
- The key spec which the application passed to the generatePublic(KeySpec)
method of the key factory.keySpec
argument.java.security.spec.InvalidKeySpecException
- If the given key spec is invalid in this context.public abstract java.security.spec.KeySpec handleKeyFactoryGeneratePrivate(java.lang.String algorithm, java.security.spec.KeySpec keySpec) throws java.security.spec.InvalidKeySpecException
generatePrivate(KeySpec)
method implementation. The factory proceeds with the
KeySpec
returned by this method. It does not use the original any longer.
This allows the key handler to translate the given key spec into a
PKCS11KeySpec
for a default provider instance.
algorithm
- The algorithm name of the key factory; e.g. RSA.keySpec
- The key spec which the application passed to the generatePrivate(KeySpec)
method of the key factory.keySpec
argument.java.security.spec.InvalidKeySpecException
- If the given key spec is invalid in this context.public abstract java.security.Key handleKeyFactoryTranslateKey(java.lang.String algorithm, java.security.Key key) throws java.security.InvalidKeyException
translateKey(Key)
method implementation. The factory proceeds with the Key
returned by this method.
It does not use the original any longer.
This allows the key handler to translate the given key into a
IAIKPKCS11Key
for a default provider instance.
algorithm
- The algorithm name of the key factory; e.g. RSA.key
- The key which the application passed to the translateKey(Key)
method of
the key factory.key
argument.java.security.InvalidKeyException
- If the given key is invalid in this context.public abstract java.security.spec.KeySpec handleSecretKeyFactoryGenerateSecret(java.lang.String algorithm, java.security.spec.KeySpec keySpec) throws java.security.spec.InvalidKeySpecException
generateSecret(KeySpec)
method
implementation. The factory proceeds with the KeySpec
returned by this method. It
does not use the original any longer.
This allows the key handler to translate the given key spec into a
PKCS11KeySpec
for a default provider instance.
algorithm
- The algorithm name of the key factory; e.g. DESede or AES.keySpec
- The key spec which the application passed to the generateSecret(KeySpec)
method of the secret key factory.keySpec
argument.java.security.spec.InvalidKeySpecException
- If the given key spec is invalid in this context.public abstract javax.crypto.SecretKey handleSecretKeyFactoryTranslateKey(java.lang.String algorithm, javax.crypto.SecretKey key) throws java.security.InvalidKeyException
translateKey(SecretKey)
method
implementation. The factory proceeds with the Key
returned by this method. It does
not use the original any longer.
This allows the key handler to translate the given key into a
IAIKPKCS11Key
for a default provider instance.
algorithm
- The algorithm name of the key factory; e.g. DESede or AES.key
- The key which the application passed to the translateKey(SecretKey)
method of the secret key factory.key
argument.java.security.InvalidKeyException
- If the given key is invalid in this context.public abstract iaik.pkcs.pkcs11.objects.KeyPair getKeyPairGeneratorTemplate(java.lang.String algorithm, int keySize) throws java.security.InvalidParameterException
algorithm
- The key-pair generation algorithm; e.g. RSA
.keySize
- The key size in bits; e.g. 1024. Use -1 to use the default key size.java.security.InvalidParameterException
- If the key size is invalid.public abstract iaik.pkcs.pkcs11.objects.KeyPair getKeyPairGeneratorTemplate(java.lang.String algorithm, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidAlgorithmParameterException
This method only gets parameters which are not of type
PKCS11KeyPairGenerationSpec
.
The key-pair generators handle such parameter directly. For example, they will get the values
from the parameters object enclosed by the PKCS11KeyPairGenerationSpec object and put the
values into the key template. For instance, if the application provides a
PKCS11KeyPairGenerationSpec object with an enclosed
javax.crypto.spec.DHParameterSpec
object to a DH key-pair generator, the generator
will itself put the P and G value into the public key template and the L value into the private
key template.
algorithm
- The key-pair generation algorithm; e.g. RSA
.params
- The algorithm parameters; e.g. javax.crypto.spec.DHParameterSpec
.java.security.InvalidAlgorithmParameterException
- If the parameters are invalid for this algorithm.public abstract iaik.pkcs.pkcs11.objects.SecretKey getKeyGeneratorTemplate(java.lang.String algorithm, int keySize) throws java.security.InvalidParameterException
algorithm
- The key generation algorithm; e.g. AES
.keySize
- The key size in bits; e.g. 128. Use -1 to use the default key size.java.security.InvalidParameterException
- If the key size is invalid.public abstract iaik.pkcs.pkcs11.objects.SecretKey getKeyGeneratorTemplate(java.lang.String algorithm, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidAlgorithmParameterException
This method only gets parameters which are not of type
PKCS11KeyGenerationSpec
.
The key generators handle such parameter directly. For example, they will get the values from the parameters object enclosed by the PKCS11KeyGenerationSpec object and put the values into the key template.
algorithm
- The key generation algorithm; e.g. AES
.params
- The algorithm parameters>.java.security.InvalidAlgorithmParameterException
- If the parameters are invalid for this algorithm.IAIK JavaSecurity Website https://jce.iaik.tugraz.at/
IAIK at Graz University of Technology, Austria, Europe
Copyright 2001-2023 IAIK, Graz University of Technology, Inffeldgasse 16a, 8010 Graz, Austria. All Rights Reserved. Version 1.9.4