Package com.amazonaws.encryptionsdk.jce
Class KeyStoreProvider
- java.lang.Object
-
- com.amazonaws.encryptionsdk.MasterKeyProvider<JceMasterKey>
-
- com.amazonaws.encryptionsdk.jce.KeyStoreProvider
-
public class KeyStoreProvider extends MasterKeyProvider<JceMasterKey>
ThisMasterKeyProvider
provides keys backed by a JCEKeyStore
. Please seedecryptDataKey(CryptoAlgorithm, Collection, Map)
for an of how decryption is managed and seegetMasterKeysForEncryption(MasterKeyRequest)
for an explanation of how encryption is managed.
-
-
Constructor Summary
Constructors Constructor Description KeyStoreProvider(KeyStore keystore, KeyStore.ProtectionParameter protection, String providerName, String wrappingAlgorithm)
Creates an instance of this class usingwrappingAlgorithm
which will work for decrypt only.KeyStoreProvider(KeyStore keystore, KeyStore.ProtectionParameter protection, String providerName, String wrappingAlgorithm, String... aliasNames)
Creates an instance of this class usingwrappingAlgorithm
which will encrypt data to the keys specified byaliasNames
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataKey<JceMasterKey>
decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext)
Attempts to decrypts theencryptedDataKeys
by first iterating through allaliasNames
specified in the constructor and then over all other compatible keys in theKeyStore
.String
getDefaultProviderId()
Returns "JavaKeyStore".JceMasterKey
getMasterKey(String provider, String keyId)
Returns aJceMasterKey
corresponding to the entry in theKeyStore
with the specified alias and compatible algorithm.List<JceMasterKey>
getMasterKeysForEncryption(MasterKeyRequest request)
ReturnsJceMasterKey
s corresponding to thealiasNames
passed into the constructor.-
Methods inherited from class com.amazonaws.encryptionsdk.MasterKeyProvider
buildCannotDecryptDksException, buildCannotDecryptDksException, buildCannotDecryptDksException, canProvide, getMasterKey
-
-
-
-
Constructor Detail
-
KeyStoreProvider
public KeyStoreProvider(KeyStore keystore, KeyStore.ProtectionParameter protection, String providerName, String wrappingAlgorithm)
Creates an instance of this class usingwrappingAlgorithm
which will work for decrypt only.
-
KeyStoreProvider
public KeyStoreProvider(KeyStore keystore, KeyStore.ProtectionParameter protection, String providerName, String wrappingAlgorithm, String... aliasNames)
Creates an instance of this class usingwrappingAlgorithm
which will encrypt data to the keys specified byaliasNames
.
-
-
Method Detail
-
getMasterKey
public JceMasterKey getMasterKey(String provider, String keyId) throws UnsupportedProviderException, NoSuchMasterKeyException
Returns aJceMasterKey
corresponding to the entry in theKeyStore
with the specified alias and compatible algorithm.- Specified by:
getMasterKey
in classMasterKeyProvider<JceMasterKey>
- Returns:
- Throws:
UnsupportedProviderException
- if this object cannot returnMasterKey
s associated with the given providerNoSuchMasterKeyException
- if this object cannot find (and thus construct) theMasterKey
associated withkeyId
-
getDefaultProviderId
public String getDefaultProviderId()
Returns "JavaKeyStore".- Specified by:
getDefaultProviderId
in classMasterKeyProvider<JceMasterKey>
-
getMasterKeysForEncryption
public List<JceMasterKey> getMasterKeysForEncryption(MasterKeyRequest request)
ReturnsJceMasterKey
s corresponding to thealiasNames
passed into the constructor.- Specified by:
getMasterKeysForEncryption
in classMasterKeyProvider<JceMasterKey>
-
decryptDataKey
public DataKey<JceMasterKey> decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext) throws UnsupportedProviderException, AwsCryptoException
Attempts to decrypts theencryptedDataKeys
by first iterating through allaliasNames
specified in the constructor and then over all other compatible keys in theKeyStore
. This includesTrustedCertificates
as well as standard key entries.- Specified by:
decryptDataKey
in classMasterKeyProvider<JceMasterKey>
- Returns:
- a DataKey if one can be decrypted, otherwise returns
null
- Throws:
UnsupportedProviderException
- if theencryptedDataKey
is associated with an unsupported providerCannotUnwrapDataKeyException
- if theencryptedDataKey
cannot be decryptedAwsCryptoException
-
-