Package de.hda.fbi.ucs.eucrite
Class KeyManager
java.lang.Object
de.hda.fbi.ucs.eucrite.KeyManager
- Direct Known Subclasses:
StatefulKeyManager
,StatelessKeyManager
public abstract class KeyManager extends Object
The KeyManager handles a
stateless
or stateful
key pair or secret key and the corresponding
certificates. To initialize a KeyManager object, the static methods
loadKey(StorageParameters storageParameters)
or createNewKey(AlgorithmParameters algorithmParameters, StorageParameters storageParameters)
can be used to load existing key material or create new key material.
See StatelessKeyManager
and
StatefulKeyManager
for details about the different KeyManagers.
- Author:
- Alexander Zeier
-
Constructor Summary
Constructors Constructor Description KeyManager()
-
Method Summary
Modifier and Type Method Description StatefulKeyManager
castToStatefulKeyManager()
Casts this KeyManager to an instance ofStatefulKeyManager
in case some of the special functionality only provided by a StatefulKeyManager is needed.static KeyManager
createNewKey(AlgorithmParameters algorithmParameters, StorageParameters storageParameters)
Creates a KeyManager with a newly generated key pair.static Certificate
createSelfSignedCertificate(PublicKey publicKey, PrivateKey privateKey)
Creates a self signed certificate for test purposes.String
getAlgorithm()
Get the algorithm name.Certificate
getCertificate()
Get the certificate associated with the public key managed by the KeyManager.PublicKey
getPublicKey()
Get the public part of the key pair managed by the KeyManager.SecretKey
getSecretKey()
Get the secret key managed by the KeyManager.static KeyManager
loadKey(StorageParameters storageParameters)
Creates a KeyManager with existing key material.void
updateKeyInAdvance(int numberOfUpdates)
This method should only be implemented for stateful schemes.
-
Constructor Details
-
KeyManager
public KeyManager()
-
-
Method Details
-
createNewKey
public static KeyManager createNewKey(AlgorithmParameters algorithmParameters, StorageParameters storageParameters) throws NoSuchAlgorithmException, FileAlreadyExistsExceptionCreates a KeyManager with a newly generated key pair. The location of the key pair and other information to access the key pair are given by thestorageParameters
. The algorithm to use with all necessary parameters are given by the {link AlgorithmParameters algorithmParameters}. Depending on the algorithm, aStatelessKeyManager
or aStatefulKeyManager
is created.Example (creating a key pair):
AlgorithmParameters parameters = AlgorithmParameters.Template.Hybrid_Encryption.Security_Level.HIGH.getParameters(); KeystoreParameters keystoreParameters = new KeystoreParameters("data/key", "123456"); KeyManager keyManager = KeyManager.createNewKeyPair(algorithmParameters, keystoreParameters);
- Parameters:
algorithmParameters
- The parameters defining the signature algorithm with the necessary parameters.storageParameters
- The parameters defining the storage location and everything else necessary to access the key pair.- Returns:
- An instance of the KeyManager.
- Throws:
FileAlreadyExistsException
- If the file already exists.NoSuchAlgorithmException
- If the key pair belongs to an algorithm that is not supported by this KeyManager.
-
loadKey
public static KeyManager loadKey(StorageParameters storageParameters) throws FileNotFoundException, NoSuchAlgorithmException, IllegalArgumentExceptionCreates a KeyManager with existing key material. The location of the key pair and other information to access the key material are given by thestorageParameters
. Depending on the type of keys, aStatelessKeyManager
or aStatefulKeyManager
is created.Example (loading an key(s)):
KeystoreParameters keystoreParameters = new KeystoreParameters("data/key", "123456"); KeyManager keyManager = KeyManager.loadKey(keystoreParameters);
- Parameters:
storageParameters
- The parameters defining the storage location and everything else necessary to access the key pair.- Returns:
- The KeyManager
- Throws:
FileNotFoundException
- If the file couldn't be found.NoSuchAlgorithmException
- If the key pair belongs to an algorithm that is not supported by this KeyManager.IllegalArgumentException
-
getAlgorithm
Get the algorithm name.- Returns:
- The name of the algorithm.
-
getPublicKey
Get the public part of the key pair managed by the KeyManager.- Returns:
- The public key.
-
getSecretKey
Get the secret key managed by the KeyManager.- Returns:
- The secret key.
-
getCertificate
Get the certificate associated with the public key managed by the KeyManager.- Returns:
- The certificate.
-
castToStatefulKeyManager
Casts this KeyManager to an instance ofStatefulKeyManager
in case some of the special functionality only provided by a StatefulKeyManager is needed.- Returns:
- This KeyManager as an instance of
StatefulKeyManager
.
-
updateKeyInAdvance
public void updateKeyInAdvance(int numberOfUpdates)This method should only be implemented for stateful schemes. To provide an identical interface for all schemes, this method can be called from stateless schemes with no effect.- Parameters:
numberOfUpdates
- The number of times the private key is updated in advanced.- See Also:
More information about stateful signature schemes.
-
createSelfSignedCertificate
public static Certificate createSelfSignedCertificate(PublicKey publicKey, PrivateKey privateKey) throws IOException, CertificateException, InvalidKeyException, SignatureException, NoSuchProviderException, NoSuchAlgorithmExceptionCreates a self signed certificate for test purposes.- Parameters:
publicKey
- the public key that should be contained in the certificate.privateKey
- the private key used to sign the certificate.- Returns:
- The self signed certificate.
- Throws:
IOException
- if an I/O error occurs.CertificateException
- if the certificate creation failed.InvalidKeyException
SignatureException
NoSuchProviderException
NoSuchAlgorithmException
-