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>
ThisMasterKeyProviderprovides 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 usingwrappingAlgorithmwhich will work for decrypt only.KeyStoreProvider(KeyStore keystore, KeyStore.ProtectionParameter protection, String providerName, String wrappingAlgorithm, String... aliasNames)Creates an instance of this class usingwrappingAlgorithmwhich 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 theencryptedDataKeysby first iterating through allaliasNamesspecified in the constructor and then over all other compatible keys in theKeyStore.StringgetDefaultProviderId()Returns "JavaKeyStore".JceMasterKeygetMasterKey(String provider, String keyId)Returns aJceMasterKeycorresponding to the entry in theKeyStorewith the specified alias and compatible algorithm.List<JceMasterKey>getMasterKeysForEncryption(MasterKeyRequest request)ReturnsJceMasterKeys corresponding to thealiasNamespassed 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 usingwrappingAlgorithmwhich 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 usingwrappingAlgorithmwhich will encrypt data to the keys specified byaliasNames.
-
-
Method Detail
-
getMasterKey
public JceMasterKey getMasterKey(String provider, String keyId) throws UnsupportedProviderException, NoSuchMasterKeyException
Returns aJceMasterKeycorresponding to the entry in theKeyStorewith the specified alias and compatible algorithm.- Specified by:
getMasterKeyin classMasterKeyProvider<JceMasterKey>- Returns:
- Throws:
UnsupportedProviderException- if this object cannot returnMasterKeys associated with the given providerNoSuchMasterKeyException- if this object cannot find (and thus construct) theMasterKeyassociated withkeyId
-
getDefaultProviderId
public String getDefaultProviderId()
Returns "JavaKeyStore".- Specified by:
getDefaultProviderIdin classMasterKeyProvider<JceMasterKey>
-
getMasterKeysForEncryption
public List<JceMasterKey> getMasterKeysForEncryption(MasterKeyRequest request)
ReturnsJceMasterKeys corresponding to thealiasNamespassed into the constructor.- Specified by:
getMasterKeysForEncryptionin classMasterKeyProvider<JceMasterKey>
-
decryptDataKey
public DataKey<JceMasterKey> decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext) throws UnsupportedProviderException, AwsCryptoException
Attempts to decrypts theencryptedDataKeysby first iterating through allaliasNamesspecified in the constructor and then over all other compatible keys in theKeyStore. This includesTrustedCertificatesas well as standard key entries.- Specified by:
decryptDataKeyin classMasterKeyProvider<JceMasterKey>- Returns:
- a DataKey if one can be decrypted, otherwise returns
null - Throws:
UnsupportedProviderException- if theencryptedDataKeyis associated with an unsupported providerCannotUnwrapDataKeyException- if theencryptedDataKeycannot be decryptedAwsCryptoException
-
-