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 Details

    • KeyStoreHelper

      public KeyStoreHelper(@NonNull @NonNull Path keyStorePath, char @NonNull [] 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, char @NonNull [] 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, char @NonNull [] 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