Class KeyStoreHelper

java.lang.Object
com.amilesend.client.crypto.KeyStoreHelper

public class KeyStoreHelper extends Object
Helper that manages storage of symmetric keys to a key store file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    KeyStoreHelper(@NonNull Path keyStorePath, @lombok.NonNull char[] keyStorePassword)
    Creates a new KeyStoreHelper instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    getSecretKey(String alias, @lombok.NonNull char[] keyPassword)
    Gets the key with the given alias and associated keyPassword from the key store.
    void
    saveSecretKey(String alias, @NonNull SecretKey key, @lombok.NonNull char[] keyPassword)
    Saves the given key to the key store.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KeyStoreHelper

      public KeyStoreHelper(@NonNull @NonNull Path keyStorePath, @NonNull @lombok.NonNull char[] keyStorePassword)
      Creates a new KeyStoreHelper instance.
      Parameters:
      keyStorePath - The path to the key store used to store the symmetric key used for encryption.
      keyStorePassword - The password to access the key store.
  • Method Details

    • saveSecretKey

      public void saveSecretKey(String alias, @NonNull @NonNull SecretKey key, @NonNull @lombok.NonNull char[] keyPassword) throws KeyStoreHelperException
      Saves the given key to the key store. Notes:
      • The key is referenced by the alias and is individually protected via the given keyPassword.
      • If the key store file does not exist, this method attempts to create a new key store to the defined keyStorePath prior to saving the key.
      Parameters:
      alias - the alias to store the key as
      key - the key itself
      keyPassword - the password that is specific to the key
      Throws:
      KeyStoreHelperException - if an error occurred while saving the key to the key store
    • getSecretKey

      public SecretKey getSecretKey(String alias, @NonNull @lombok.NonNull char[] keyPassword) throws KeyStoreHelperException
      Gets the key with the given alias and associated keyPassword from the key store. Notes:
      • If the key store file does not exist, then this method attempts to create a new key store to the defined keyStorePath. In this case, null will be returned as the given alias references no existing key.
      • If the key does not exist for the given alias, then null will be returned.
      Parameters:
      alias - the alias for the key
      keyPassword - the associated password that protects the key
      Returns:
      the key, or null
      Throws:
      KeyStoreHelperException - if an error occurred while retrieving the key