Package com.amazonaws.encryptionsdk.kms
Class KmsMasterKeyProvider
- java.lang.Object
-
- com.amazonaws.encryptionsdk.MasterKeyProvider<KmsMasterKey>
-
- com.amazonaws.encryptionsdk.kms.KmsMasterKeyProvider
-
- All Implemented Interfaces:
KmsMethods
public class KmsMasterKeyProvider extends MasterKeyProvider<KmsMasterKey> implements KmsMethods
ProvidesMasterKeys backed by the AWS Key Management Service. This object is regional and if you want to use keys from multiple regions, you'll need multiple copies of this object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKmsMasterKeyProvider.Builderstatic interfaceKmsMasterKeyProvider.RegionalClientSupplier
-
Constructor Summary
Constructors Constructor Description KmsMasterKeyProvider()Deprecated.The default region set by this constructor is subject to change.KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentials creds)Deprecated.The default region set by this constructor is subject to change.KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentialsProvider creds)Deprecated.The default region set by this constructor is subject to change.KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentialsProvider creds, com.amazonaws.regions.Region region, com.amazonaws.ClientConfiguration clientConfiguration, String keyId)Deprecated.This constructor implicitly configures the KMS Master Key Provider to perform discovery behavior on decrypt, which is a behavior that should be constructed explicitly.KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentialsProvider creds, com.amazonaws.regions.Region region, com.amazonaws.ClientConfiguration clientConfiguration, List<String> keyIds)Deprecated.This constructor implicitly configures the KMS Master Key Provider to perform discovery behavior on decrypt, which is a behavior that should be constructed explicitly.KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentialsProvider creds, String keyId)Deprecated.The default region set by this constructor is subject to change.KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentials creds, String keyId)Deprecated.The default region set by this constructor is subject to change.KmsMasterKeyProvider(com.amazonaws.services.kms.AWSKMS kms, com.amazonaws.regions.Region region, List<String> keyIds)Deprecated.This constructor modifies the passed-in KMS client by setting its region.KmsMasterKeyProvider(String keyId)Deprecated.The default region set by this constructor is subject to change.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddGrantToken(String grantToken)Deprecated.This method is inherently not thread safe.static KmsMasterKeyProvider.Builderbuilder()DataKey<KmsMasterKey>decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext)Iterates throughencryptedDataKeysand returns the first one which can be successfully decrypted.StringgetDefaultProviderId()Returns "aws-kms"List<String>getGrantTokens()Returns the grantTokens which this object sends to KMS when calling it.KmsMasterKeygetMasterKey(String provider, String keyId)Returns the specifiedMasterKeyif possible.List<KmsMasterKey>getMasterKeysForEncryption(MasterKeyRequest request)Returns all CMKs provided to the constructor of this object.voidsetGrantTokens(List<String> grantTokens)Deprecated.This method is inherently not thread safe.KmsMasterKeyProviderwithGrantTokens(String... grantTokens)Returns a newKmsMasterKeyProviderthat is configured identically to this one, except with the given list of grant tokens.KmsMasterKeyProviderwithGrantTokens(List<String> grantTokens)Returns a newKmsMasterKeyProviderthat is configured identically to this one, except with the given list of grant tokens.-
Methods inherited from class com.amazonaws.encryptionsdk.MasterKeyProvider
buildCannotDecryptDksException, buildCannotDecryptDksException, buildCannotDecryptDksException, canProvide, getMasterKey
-
-
-
-
Constructor Detail
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider()
Deprecated.The default region set by this constructor is subject to change. Use the builder method to construct instances of this class for better control.Returns an instance of this object with default settings, default credentials, and configured to talk to theRegions.DEFAULT_REGION.
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider(String keyId)
Deprecated.The default region set by this constructor is subject to change. Use the builder method to construct instances of this class for better control.Returns an instance of this object with default settings and credentials configured to speak to the region specified bykeyId(if specified). Data will be protected withkeyIdas appropriate.The default region will be set to that of the given key ID, or to the AWS SDK default region if a bare key ID or alias is passed.
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentials creds, String keyId)
Deprecated.The default region set by this constructor is subject to change. Use the builder method to construct instances of this class for better control.Returns an instance of this object with default settings configured to speak to the region specified bykeyId(if specified). Data will be protected withkeyIdas appropriate.
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentialsProvider creds, String keyId)
Deprecated.The default region set by this constructor is subject to change. Use the builder method to construct instances of this class for better control.Returns an instance of this object with default settings configured to speak to the region specified bykeyId(if specified). Data will be protected withkeyIdas appropriate.The default region will be set to that of the given key ID, or to the AWS SDK default region if a bare key ID or alias is passed.
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentials creds)
Deprecated.The default region set by this constructor is subject to change. Use the builder method to construct instances of this class for better control.Returns an instance of this object with default settings and configured to talk to theRegions.DEFAULT_REGION.
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentialsProvider creds)
Deprecated.The default region set by this constructor is subject to change. Use the builder method to construct instances of this class for better control.Returns an instance of this object with default settings and configured to talk to theRegions.DEFAULT_REGION.
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentialsProvider creds, com.amazonaws.regions.Region region, com.amazonaws.ClientConfiguration clientConfiguration, String keyId)
Deprecated.This constructor implicitly configures the KMS Master Key Provider to perform discovery behavior on decrypt, which is a behavior that should be constructed explicitly. To create a KMS Master Key Provider that continues to perform discovery on decrypt, useKmsMasterKeyProvider.Builder.buildDiscovery()orKmsMasterKeyProvider.Builder.buildDiscovery(DiscoveryFilter). To create a KMS Master Key Provider that restricts what keys to attempt decryption with to a set of configured keys, useKmsMasterKeyProvider.Builder.buildStrict(List).Returns an instance of this object with the supplied configuration and credentials.keyIdwill be used to protect data.
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider(com.amazonaws.auth.AWSCredentialsProvider creds, com.amazonaws.regions.Region region, com.amazonaws.ClientConfiguration clientConfiguration, List<String> keyIds)
Deprecated.This constructor implicitly configures the KMS Master Key Provider to perform discovery behavior on decrypt, which is a behavior that should be constructed explicitly. To create a KMS Master Key Provider that continues to perform discovery on decrypt, useKmsMasterKeyProvider.Builder.buildDiscovery()orKmsMasterKeyProvider.Builder.buildDiscovery(DiscoveryFilter). To create a KMS Master Key Provider that restricts what keys to attempt decryption with to a set of configured keys, useKmsMasterKeyProvider.Builder.buildStrict(List).Returns an instance of this object with the supplied configuration and credentials. all keys listed inkeyIdswill be used to protect data.
-
KmsMasterKeyProvider
@Deprecated public KmsMasterKeyProvider(com.amazonaws.services.kms.AWSKMS kms, com.amazonaws.regions.Region region, List<String> keyIds)
Deprecated.This constructor modifies the passed-in KMS client by setting its region. This functionality may be removed in future releases. Use the builder to construct instances of this class instead.Returns an instance of this object with the supplied client and region; the client will be configured to use the provided region. All keys listed inkeyIdswill be used to protect data.
-
-
Method Detail
-
builder
public static KmsMasterKeyProvider.Builder builder()
-
getDefaultProviderId
public String getDefaultProviderId()
Returns "aws-kms"- Specified by:
getDefaultProviderIdin classMasterKeyProvider<KmsMasterKey>
-
getMasterKey
public KmsMasterKey getMasterKey(String provider, String keyId) throws UnsupportedProviderException, NoSuchMasterKeyException
Description copied from class:MasterKeyProviderReturns the specifiedMasterKeyif possible.- Specified by:
getMasterKeyin classMasterKeyProvider<KmsMasterKey>- Returns:
- Throws:
UnsupportedProviderException- if this object cannot returnMasterKeys associated with the given providerNoSuchMasterKeyException- if this object cannot find (and thus construct) theMasterKeyassociated withkeyId
-
getMasterKeysForEncryption
public List<KmsMasterKey> getMasterKeysForEncryption(MasterKeyRequest request)
Returns all CMKs provided to the constructor of this object.- Specified by:
getMasterKeysForEncryptionin classMasterKeyProvider<KmsMasterKey>
-
decryptDataKey
public DataKey<KmsMasterKey> decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext) throws AwsCryptoException
Description copied from class:MasterKeyProviderIterates throughencryptedDataKeysand returns the first one which can be successfully decrypted.- Specified by:
decryptDataKeyin classMasterKeyProvider<KmsMasterKey>- Returns:
- a DataKey if one can be decrypted, otherwise returns
null - Throws:
UnsupportedProviderException- if theencryptedDataKeyis associated with an unsupported providerCannotUnwrapDataKeyException- if theencryptedDataKeycannot be decryptedAwsCryptoException
-
setGrantTokens
@Deprecated public void setGrantTokens(List<String> grantTokens)
Deprecated.This method is inherently not thread safe. UseKmsMasterKey.setGrantTokens(List)instead.KmsMasterKeyProviders constructed using the builder will throw an exception on attempts to modify the list of grant tokens.Description copied from interface:KmsMethodsSets thegrantTokenswhich should be submitted to KMS when calling it.- Specified by:
setGrantTokensin interfaceKmsMethods
-
getGrantTokens
public List<String> getGrantTokens()
Description copied from interface:KmsMethodsReturns the grantTokens which this object sends to KMS when calling it.- Specified by:
getGrantTokensin interfaceKmsMethods
-
addGrantToken
@Deprecated public void addGrantToken(String grantToken)
Deprecated.This method is inherently not thread safe. UsewithGrantTokens(List)orKmsMasterKey.setGrantTokens(List)instead.KmsMasterKeyProviders constructed using the builder will throw an exception on attempts to modify the list of grant tokens.Description copied from interface:KmsMethodsAddsgrantTokento the list of grantTokens sent to KMS when this class calls it.- Specified by:
addGrantTokenin interfaceKmsMethods
-
withGrantTokens
public KmsMasterKeyProvider withGrantTokens(List<String> grantTokens)
Returns a newKmsMasterKeyProviderthat is configured identically to this one, except with the given list of grant tokens. The grant token list in the returned provider is immutable (but can be further overridden by invoking withGrantTokens again).- Parameters:
grantTokens-- Returns:
-
withGrantTokens
public KmsMasterKeyProvider withGrantTokens(String... grantTokens)
Returns a newKmsMasterKeyProviderthat is configured identically to this one, except with the given list of grant tokens. The grant token list in the returned provider is immutable (but can be further overridden by invoking withGrantTokens again).- Parameters:
grantTokens-- Returns:
-
-