Package com.amilesend.client.crypto
Class KeyStoreHelper
java.lang.Object
com.amilesend.client.crypto.KeyStoreHelper
Helper that manages storage of symmetric keys to a key store file.
-
Constructor Summary
ConstructorsConstructorDescriptionKeyStoreHelper
(@NonNull Path keyStorePath, @lombok.NonNull char[] keyStorePassword) Creates a newKeyStoreHelper
instance. -
Method Summary
Modifier and TypeMethodDescriptiongetSecretKey
(String alias, @lombok.NonNull char[] keyPassword) Gets the key with the givenalias
and associatedkeyPassword
from the key store.void
saveSecretKey
(String alias, @NonNull SecretKey key, @lombok.NonNull char[] keyPassword) Saves the givenkey
to the key store.
-
Constructor Details
-
KeyStoreHelper
public KeyStoreHelper(@NonNull @NonNull Path keyStorePath, @NonNull @lombok.NonNull char[] keyStorePassword) Creates a newKeyStoreHelper
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 givenkey
to the key store. Notes:- The key is referenced by the
alias
and is individually protected via the givenkeyPassword
. - 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 askey
- the key itselfkeyPassword
- the password that is specific to the key- Throws:
KeyStoreHelperException
- if an error occurred while saving the key to the key store
- The key is referenced by the
-
getSecretKey
public SecretKey getSecretKey(String alias, @NonNull @lombok.NonNull char[] keyPassword) throws KeyStoreHelperException Gets the key with the givenalias
and associatedkeyPassword
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 givenalias
references no existing key. - If the key does not exist for the given
alias
, thennull
will be returned.
- Parameters:
alias
- the alias for the keykeyPassword
- the associated password that protects the key- Returns:
- the key, or
null
- Throws:
KeyStoreHelperException
- if an error occurred while retrieving the key
- If the key store file does not exist, then this method attempts to create a new key store to the defined
-