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 Details

    • KeyManager

      public KeyManager()
  • Method Details

    • createNewKey

      public static KeyManager createNewKey​(AlgorithmParameters algorithmParameters, StorageParameters storageParameters) throws NoSuchAlgorithmException, FileAlreadyExistsException
      Creates 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 the storageParameters. The algorithm to use with all necessary parameters are given by the {link AlgorithmParameters algorithmParameters}. Depending on the algorithm, a StatelessKeyManager or a StatefulKeyManager 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

      Creates a KeyManager with existing key material. The location of the key pair and other information to access the key material are given by the storageParameters. Depending on the type of keys, a StatelessKeyManager or a StatefulKeyManager 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

      public String getAlgorithm()
      Get the algorithm name.
      Returns:
      The name of the algorithm.
    • getPublicKey

      public PublicKey getPublicKey()
      Get the public part of the key pair managed by the KeyManager.
      Returns:
      The public key.
    • getSecretKey

      public SecretKey getSecretKey()
      Get the secret key managed by the KeyManager.
      Returns:
      The secret key.
    • getCertificate

      public Certificate getCertificate()
      Get the certificate associated with the public key managed by the KeyManager.
      Returns:
      The certificate.
    • castToStatefulKeyManager

      public StatefulKeyManager castToStatefulKeyManager()
      Casts this KeyManager to an instance of StatefulKeyManager 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

      Creates 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