Interface KeyStoreService
public interface KeyStoreService
This class is responsible for creating,serializing keystores as well as reading keys from keystores but works
with concrete keystore blob.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPasswordBasedSecretKey(KeyStoreAccess keyStoreAccess, String alias, char[] secretToStore) Adds password-like secret key to keystore.createKeyStore(KeyStoreAuth keyStoreAuth, KeyCreationConfig config) Creates keystore.createKeyStore(KeyStoreAuth keyStoreAuth, KeyCreationConfig config, Map<KeyID, Optional<SecretKeyEntry>> secretKeys) Creates keystore that has additional secret keys in it.deserialize(byte[] payload, ReadStorePassword password) Reads encrypted keystore from its byte representation - decryption is done usingKeyStoreAuth.getReadStorePassword()getPrivateKey(KeyStoreAccess keyStoreAccess, KeyID keyID) Reads private key from the keystore.getPublicKeys(KeyStoreAccess keyStoreAccess) Reads public keys from the keystore.getSecretKey(KeyStoreAccess keyStoreAccess, KeyID keyID) Reads secret key from the keystore.voidremoveKey(KeyStoreAccess keyStoreAccess, String alias) Removes key that is identified byaliasfrom keystore.byte[]serialize(KeyStore store, ReadStorePassword password) Converts keystore into bytes, they are safe to be store/transferred because of encryption usingKeyStoreAuth.getReadStorePassword()updateKeyStoreReadKeyPassword(KeyStore current, KeyStoreAuth currentCredentials, KeyStoreAuth newCredentials) Updates keystore access credentials and returns new keystore with new credentials.
-
Method Details
-
createKeyStore
Creates keystore.- Parameters:
keyStoreAuth- Keys for opening keystore and reading key from itconfig- Keystore will be pre-populated with keys according to it- Returns:
- Built keystore that is ready to use
-
createKeyStore
KeyStore createKeyStore(KeyStoreAuth keyStoreAuth, KeyCreationConfig config, Map<KeyID, Optional<SecretKeyEntry>> secretKeys) Creates keystore that has additional secret keys in it.- Parameters:
keyStoreAuth- Keys for opening keystore and reading key from itconfig- Keystore will be pre-populated with keys according to itsecretKeys- Secret keys to store in keystore, if value is empty - key will be generated- Returns:
- Built keystore that is ready to use
-
updateKeyStoreReadKeyPassword
KeyStore updateKeyStoreReadKeyPassword(KeyStore current, KeyStoreAuth currentCredentials, KeyStoreAuth newCredentials) Updates keystore access credentials and returns new keystore with new credentials.- Parameters:
current- Original keystorecurrentCredentials- Oriignal keystore credentialsnewCredentials- New credentials to use- Returns:
- Cloned old keystore that can be opened using new credentials only.
-
getPublicKeys
Reads public keys from the keystore.- Parameters:
keyStoreAccess- Key to open keystore (onlyKeyStoreAuth.getReadStorePassword()is used)- Returns:
- List of public keys within the keystore
-
getPrivateKey
Reads private key from the keystore.- Parameters:
keyStoreAccess- Key to open keystore and read key, (bothKeyStoreAuth.getReadStorePassword()andKeyStoreAuth.getReadKeyPassword()are used)keyID- Private key ID to read- Returns:
- Private key associated with given ID
-
getSecretKey
Reads secret key from the keystore.- Parameters:
keyStoreAccess- Key to open keystore and read key, (bothKeyStoreAuth.getReadStorePassword()andKeyStoreAuth.getReadKeyPassword()are used)keyID- Secret key ID to read- Returns:
- Secret key associated with given ID
-
addPasswordBasedSecretKey
Adds password-like secret key to keystore.- Parameters:
keyStoreAccess- Keystore with its access detailsalias- Key alias to addsecretToStore- Key value to store in keystore (inkeyStoreAccess)
-
removeKey
Removes key that is identified byaliasfrom keystore.- Parameters:
keyStoreAccess- Keystore with its access detailsalias- Key alias to remove
-
serialize
Converts keystore into bytes, they are safe to be store/transferred because of encryption usingKeyStoreAuth.getReadStorePassword()- Parameters:
store- Keystore that will be serializedpassword- Encrypts byte sequence- Returns:
- Encrypted serialized keystore
-
deserialize
Reads encrypted keystore from its byte representation - decryption is done usingKeyStoreAuth.getReadStorePassword()- Parameters:
payload- Bytes to read frompassword- Decrypts byte sequence- Returns:
- Decrypted keystore
-