Class KeyManager

java.lang.Object
alpine.security.crypto.KeyManager

public final class KeyManager extends Object
Class that manages Alpine-generated default private, public, and secret keys.
Since:
1.0.0
Author:
Steve Springett
  • Method Details

    • getInstance

      public static KeyManager getInstance()
      Returns an INSTANCE of the KeyManager.
      Returns:
      an instance of the KeyManager
      Since:
      1.0.0
    • generateKeyPair

      public KeyPair generateKeyPair() throws NoSuchAlgorithmException
      Generates a key pair.
      Returns:
      a KeyPair (public / private keys)
      Throws:
      NoSuchAlgorithmException - if the algorithm cannot be found
      Since:
      1.0.0
    • generateSecretKey

      public SecretKey generateSecretKey() throws NoSuchAlgorithmException
      Generates a secret key.
      Returns:
      a SecretKey
      Throws:
      NoSuchAlgorithmException - if the algorithm cannot be found
      Since:
      1.0.0
    • save

      public void save(KeyPair keyPair) throws IOException
      Saves a key pair.
      Parameters:
      keyPair - the key pair to save
      Throws:
      IOException - if the files cannot be written
      Since:
      1.0.0
    • save

      @Deprecated(forRemoval=true) public void save(SecretKey key) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Saves a secret key.
      Parameters:
      key - the SecretKey to save
      Throws:
      IOException - if the file cannot be written
      Since:
      1.0.0
    • saveEncoded

      public void saveEncoded(SecretKey key) throws IOException
      Saves a secret key in encoded format.
      Parameters:
      key - the SecretKey to save
      Throws:
      IOException - if the file cannot be written
      Since:
      2.2.0
    • keyPairExists

      public boolean keyPairExists()
      Checks to see if the key pair exists. Both (public and private) need to exist to return true.
      Returns:
      true if keypair exists, false if not
      Since:
      1.0.0
    • secretKeyExists

      public boolean secretKeyExists()
      Checks to see if the secret key exists.
      Returns:
      true if secret key exists, false if not
      Since:
      1.0.0
    • getKeyPair

      public KeyPair getKeyPair()
      Returns the keypair.
      Returns:
      the KeyPair
      Since:
      1.0.0
    • getPublicKey

      public PublicKey getPublicKey()
      Returns only the public key.
      Returns:
      the PublicKey
      Since:
      1.0.0
    • getPrivateKey

      public PrivateKey getPrivateKey()
      Returns only the private key.
      Returns:
      the PrivateKey
      Since:
      1.0.0
    • getSecretKey

      public SecretKey getSecretKey()
      Returns the secret key.
      Returns:
      the SecretKey
      Since:
      1.0.0
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException