public abstract class PKCS11SecretKeyFactory extends javax.crypto.SecretKeyFactorySpi implements PKCS11EngineClass
Modifier and Type | Field and Description |
---|---|
protected PKCS11KeySpec |
pkcs11KeySpec_
The specification how to generate the key.
|
protected boolean |
pkcs11OperationInitialized_
Indicates, if the PKCS#11 signature/verify is already initialized for the next operation round.
|
protected iaik.pkcs.pkcs11.Session |
session_
The session this object works with.
|
protected javax.crypto.SecretKeyFactory |
softwareDelegate_
This is the software delegate object to use, if the provided key spec is not the key spec for a
PKCS#11 key.
|
protected TokenManager |
tokenManager_
Token manager used to login session, if required.
|
Constructor and Description |
---|
PKCS11SecretKeyFactory()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected java.security.Key |
createKey(iaik.pkcs.pkcs11.objects.Object keyCreationTemplate)
This method creates a Java key from the given key creation template.
|
protected javax.crypto.SecretKey |
engineGenerateSecret(java.security.spec.KeySpec keySpec)
Converts the given key specification (key material) into a SecretKey object.
|
protected java.security.spec.KeySpec |
engineGetKeySpec(javax.crypto.SecretKey key,
java.lang.Class keySpecClass)
Returns a specification (key material) of the given key object.
|
protected javax.crypto.SecretKey |
engineTranslateKey(javax.crypto.SecretKey key)
Translates a key object of some unknown or untrusted provider into a secret key object of this
key factory.
|
protected void |
finalize()
Tries to close the used session.
|
protected void |
finalizePkcs11Operation()
The internal session finalization method, if the current operation has been finished.
|
protected abstract java.lang.String |
getAlgorithmName()
Get the (default) algorithm name of this factory.
|
protected abstract java.lang.String |
getSoftwareDelegateAlgorithm()
Return the name of the software algorithm to use, if this object must use a softwre delegation
object.
|
protected void |
initializePkcs11Operation()
The internal session initialization method, if all necessary member variables are set.
|
protected void |
initializeSession()
Sets up an appropriate session.
|
protected void |
initializeSoftwareDelegate()
Initialize the software delegate key factory and store a reference in
softwareDelegate_ . |
protected boolean |
isSessionAppropriate(iaik.pkcs.pkcs11.Session session,
PKCS11KeySpec pkcs11KeySpec)
Checks, if the given session is appropriate for use accodring to the given key spec.
|
boolean |
isSupportedBy(TokenManager tokenManager)
Check, if the current token of the given token manager supports the required features for this
engine class.
|
protected abstract javax.crypto.SecretKey |
pkcs11GenerateSecret(java.security.spec.KeySpec keySpec)
Converts the given key specification (key material) into a SecretKey object.
|
protected abstract java.security.spec.KeySpec |
pkcs11GetKeySpec(javax.crypto.SecretKey key,
java.lang.Class keySpecClass)
Returns a specification (key material) of the given key object.
|
protected javax.crypto.SecretKey |
pkcs11TranslateKey(javax.crypto.SecretKey key)
Translates a key object of some unknown or untrusted provider into a secret key object of this
key factory.
|
protected TokenManager tokenManager_
protected iaik.pkcs.pkcs11.Session session_
protected boolean pkcs11OperationInitialized_
protected PKCS11KeySpec pkcs11KeySpec_
protected javax.crypto.SecretKeyFactory softwareDelegate_
public boolean isSupportedBy(TokenManager tokenManager)
isSupportedBy
in interface PKCS11EngineClass
tokenManager
- The token manager. Used to get information about the current token.protected javax.crypto.SecretKey engineGenerateSecret(java.security.spec.KeySpec keySpec) throws java.security.spec.InvalidKeySpecException
engineGenerateSecret
in class javax.crypto.SecretKeyFactorySpi
keySpec
- the specification (key material) to be converted into SecretKey representation.java.security.spec.InvalidKeySpecException
- if the given key material cannot be converted into a SecretKey object by this key
factorySecretKeyFactorySpi.engineGenerateSecret(KeySpec)
protected java.security.spec.KeySpec engineGetKeySpec(javax.crypto.SecretKey key, java.lang.Class keySpecClass) throws java.security.spec.InvalidKeySpecException
keySpec
identifies
the specification class in which the key material should be returned. It could, for example, be
SecretKeySpec.class
, to indicate that the key material should be returned in an
instance of the SecretKeySpec
class.engineGetKeySpec
in class javax.crypto.SecretKeyFactorySpi
key
- The key.keySpecClass
- The specification class in which the key material should be returned.java.security.spec.InvalidKeySpecException
- if the requested key specification is inappropriate for the given key, or the
given key cannot be dealt with (e.g., the given key has an unrecognized format).protected javax.crypto.SecretKey engineTranslateKey(javax.crypto.SecretKey key) throws java.security.InvalidKeyException
engineTranslateKey
in class javax.crypto.SecretKeyFactorySpi
key
- the key of some unknown or untrusted providerjava.security.InvalidKeyException
- if the given key cannot be translated by this key factorySecretKeyFactorySpi.engineTranslateKey(SecretKey)
protected abstract java.lang.String getAlgorithmName()
protected abstract java.lang.String getSoftwareDelegateAlgorithm()
protected abstract javax.crypto.SecretKey pkcs11GenerateSecret(java.security.spec.KeySpec keySpec) throws java.security.spec.InvalidKeySpecException
keySpec
- the specification (key material) to be converted into SecretKey representation.java.security.spec.InvalidKeySpecException
- if the given key material cannot be converted into a SecretKey object by this key
factorySecretKeyFactorySpi.engineGenerateSecret(KeySpec)
protected abstract java.security.spec.KeySpec pkcs11GetKeySpec(javax.crypto.SecretKey key, java.lang.Class keySpecClass) throws java.security.spec.InvalidKeySpecException
keySpec
identifies
the specification class in which the key material should be returned. It could, for example, be
DHPublicKeySpec.class
, to indicate that the key material should be returned in an
instance of the DHPublicKeySpec
class.key
- The key.keySpecClass
- The specification class in which the key material should be returned.java.security.spec.InvalidKeySpecException
- if the requested key specification is inappropriate for the given key, or the
given key cannot be dealt with (e.g., the given key has an unrecognized format).protected javax.crypto.SecretKey pkcs11TranslateKey(javax.crypto.SecretKey key) throws java.security.InvalidKeyException
key
- the key of some unknown or untrusted providerjava.security.InvalidKeyException
- if the given key cannot be translated by this key factorySecretKeyFactorySpi.engineTranslateKey(SecretKey)
protected java.security.Key createKey(iaik.pkcs.pkcs11.objects.Object keyCreationTemplate) throws java.security.spec.InvalidKeySpecException
keyCreationTemplate
- The template for the PKCS#11 key object.java.security.spec.InvalidKeySpecException
- If creating the PKCS#11 key fails.protected void initializeSession()
protected void initializePkcs11Operation()
protected void finalizePkcs11Operation()
protected void initializeSoftwareDelegate()
softwareDelegate_
.protected boolean isSessionAppropriate(iaik.pkcs.pkcs11.Session session, PKCS11KeySpec pkcs11KeySpec) throws iaik.pkcs.pkcs11.TokenException
session
- The seesion to check.pkcs11KeySpec
- The key spec to check against.iaik.pkcs.pkcs11.TokenException
- If getting the necessary information about the session fails.protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- If disposing the session or finalization fails.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