Package com.amazonaws.encryptionsdk.kms
Class KmsMasterKey
- java.lang.Object
-
- com.amazonaws.encryptionsdk.MasterKeyProvider<K>
-
- com.amazonaws.encryptionsdk.MasterKey<KmsMasterKey>
-
- com.amazonaws.encryptionsdk.kms.KmsMasterKey
-
- All Implemented Interfaces:
KmsMethods
public final class KmsMasterKey extends MasterKey<KmsMasterKey> implements KmsMethods
Represents a single Customer Master Key (CMK) and is used to encrypt/decrypt data withAwsCrypto
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addGrantToken(String grantToken)
AddsgrantToken
to the list of grantTokens sent to KMS when this class calls it.DataKey<KmsMasterKey>
decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext)
Iterates throughencryptedDataKeys
and returns the first one which can be successfully decrypted.DataKey<KmsMasterKey>
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
.DataKey<KmsMasterKey>
generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)
List<String>
getGrantTokens()
Returns the grantTokens which this object sends to KMS when calling it.static KmsMasterKey
getInstance(com.amazonaws.auth.AWSCredentialsProvider creds, String keyId)
Deprecated.Use aKmsMasterKeyProvider
to obtainKmsMasterKey
s.static KmsMasterKey
getInstance(com.amazonaws.auth.AWSCredentials creds, String keyId)
Deprecated.Use aKmsMasterKeyProvider
to obtainKmsMasterKey
s.String
getKeyId()
String
getProviderId()
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 Detail
-
getInstance
@Deprecated public static KmsMasterKey getInstance(com.amazonaws.auth.AWSCredentials creds, String keyId)
Deprecated.Use aKmsMasterKeyProvider
to obtainKmsMasterKey
s.
-
getInstance
@Deprecated public static KmsMasterKey getInstance(com.amazonaws.auth.AWSCredentialsProvider creds, String keyId)
Deprecated.Use aKmsMasterKeyProvider
to obtainKmsMasterKey
s.
-
getProviderId
public String getProviderId()
- Specified by:
getProviderId
in classMasterKey<KmsMasterKey>
-
getKeyId
public String 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
public void setGrantTokens(List<String> grantTokens)
Description copied from interface:KmsMethods
Sets thegrantTokens
which should be submitted to KMS when calling it.- Specified by:
setGrantTokens
in interfaceKmsMethods
-
getGrantTokens
public List<String> getGrantTokens()
Description copied from interface:KmsMethods
Returns the grantTokens which this object sends to KMS when calling it.- Specified by:
getGrantTokens
in interfaceKmsMethods
-
addGrantToken
public void addGrantToken(String grantToken)
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, AwsCryptoException
Description 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
-
-