Package com.amazonaws.encryptionsdk.kms
Class KmsMasterKey
- All Implemented Interfaces:
KmsMethods
Represents a single Customer Master Key (CMK) and is used to encrypt/decrypt data with
AwsCrypto
.
This component is not multi-Region key aware, and will treat every AWS KMS identifier as regionally isolated.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addGrantToken(String grantToken)
AddsgrantToken
to the list of grantTokens sent to KMS when this class calls it.decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext)
Iterates throughencryptedDataKeys
and returns the first one which can be successfully decrypted.encryptDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext, DataKey<?> dataKey)
Returns a new copy of the provideddataKey
which is protected by thisMasterKey
for use withalgorithm
and associated with the providedencryptionContext
.generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)
Returns the grantTokens which this object sends to KMS when calling it.getKeyId()
void
setGrantTokens(List<String> grantTokens)
Sets thegrantTokens
which should be submitted to KMS when calling it.Methods inherited from class com.amazonaws.encryptionsdk.MasterKey
canProvide, equals, getDefaultProviderId, getMasterKey, getMasterKeysForEncryption, hashCode, toString
Methods inherited from class com.amazonaws.encryptionsdk.MasterKeyProvider
buildCannotDecryptDksException, buildCannotDecryptDksException, buildCannotDecryptDksException, getMasterKey
-
Method Details
-
getProviderId
- Specified by:
getProviderId
in classMasterKey<KmsMasterKey>
-
getKeyId
- Specified by:
getKeyId
in classMasterKey<KmsMasterKey>
-
generateDataKey
public DataKey<KmsMasterKey> generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)Description copied from class:MasterKey
Generates a newDataKey
which is protected by thisMasterKey
for use withalgorithm
and associated with the providedencryptionContext
.- Specified by:
generateDataKey
in classMasterKey<KmsMasterKey>
-
setGrantTokens
Description copied from interface:KmsMethods
Sets thegrantTokens
which should be submitted to KMS when calling it.- Specified by:
setGrantTokens
in interfaceKmsMethods
-
getGrantTokens
Description copied from interface:KmsMethods
Returns the grantTokens which this object sends to KMS when calling it.- Specified by:
getGrantTokens
in interfaceKmsMethods
-
addGrantToken
Description copied from interface:KmsMethods
AddsgrantToken
to the list of grantTokens sent to KMS when this class calls it.- Specified by:
addGrantToken
in interfaceKmsMethods
-
encryptDataKey
public DataKey<KmsMasterKey> encryptDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext, DataKey<?> dataKey)Description copied from class:MasterKey
Returns a new copy of the provideddataKey
which is protected by thisMasterKey
for use withalgorithm
and associated with the providedencryptionContext
.- Specified by:
encryptDataKey
in classMasterKey<KmsMasterKey>
-
decryptDataKey
public DataKey<KmsMasterKey> decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext) throws UnsupportedProviderException, AwsCryptoExceptionDescription copied from class:MasterKeyProvider
Iterates throughencryptedDataKeys
and returns the first one which can be successfully decrypted.- Specified by:
decryptDataKey
in classMasterKeyProvider<KmsMasterKey>
- 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
-