Package com.amazonaws.encryptionsdk
Class MasterKey<K extends MasterKey<K>>
- java.lang.Object
-
- com.amazonaws.encryptionsdk.MasterKeyProvider<K>
-
- com.amazonaws.encryptionsdk.MasterKey<K>
-
- Type Parameters:
K
- the concrete type of theMasterKey
- Direct Known Subclasses:
JceMasterKey
,KmsMasterKey
public abstract class MasterKey<K extends MasterKey<K>> extends MasterKeyProvider<K>
Represents the cryptographic key used to protect theDataKey
(which, in turn, protects the data). All MasterKeys extendMasterKeyProvider
because they are all capable of providing exactly themselves. This simplifies implementation when only a singleMasterKey
is used and/or expected.
-
-
Constructor Summary
Constructors Constructor Description MasterKey()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
canProvide(String provider)
abstract DataKey<K>
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
.boolean
equals(Object obj)
TwoMasterKey
s are equal if they are instances of the exact same class and their values forkeyId
,providerId
, anddefaultProviderId
are equal.abstract DataKey<K>
generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)
String
getDefaultProviderId()
Equivalent to callinggetProviderId()
.abstract String
getKeyId()
K
getMasterKey(String provider, String keyId)
Returnsthis
ifprovider
andkeyId
matchthis
.List<K>
getMasterKeysForEncryption(MasterKeyRequest request)
Returns a list of length1
containingthis
.abstract String
getProviderId()
int
hashCode()
String
toString()
-
Methods inherited from class com.amazonaws.encryptionsdk.MasterKeyProvider
buildCannotDecryptDksException, buildCannotDecryptDksException, buildCannotDecryptDksException, decryptDataKey, getMasterKey
-
-
-
-
Method Detail
-
getProviderId
public abstract String getProviderId()
-
getDefaultProviderId
public String getDefaultProviderId()
Equivalent to callinggetProviderId()
.- Specified by:
getDefaultProviderId
in classMasterKeyProvider<K extends MasterKey<K>>
-
getKeyId
public abstract String getKeyId()
-
generateDataKey
public abstract DataKey<K> generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)
-
encryptDataKey
public abstract DataKey<K> 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
.
-
canProvide
public boolean canProvide(String provider)
- Overrides:
canProvide
in classMasterKeyProvider<K extends MasterKey<K>>
- Returns:
-
getMasterKey
public K getMasterKey(String provider, String keyId) throws UnsupportedProviderException, NoSuchMasterKeyException
Returnsthis
ifprovider
andkeyId
matchthis
. Otherwise, throws an appropriate exception.- Specified by:
getMasterKey
in classMasterKeyProvider<K extends MasterKey<K>>
- 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
-
getMasterKeysForEncryption
public List<K> getMasterKeysForEncryption(MasterKeyRequest request)
Returns a list of length1
containingthis
.- Specified by:
getMasterKeysForEncryption
in classMasterKeyProvider<K extends MasterKey<K>>
-
equals
public boolean equals(Object obj)
TwoMasterKey
s are equal if they are instances of the exact same class and their values forkeyId
,providerId
, anddefaultProviderId
are equal.
-
-