Package com.amazonaws.encryptionsdk.jce
Class JceMasterKey
- java.lang.Object
-
- com.amazonaws.encryptionsdk.MasterKeyProvider<K>
-
- com.amazonaws.encryptionsdk.MasterKey<JceMasterKey>
-
- com.amazonaws.encryptionsdk.jce.JceMasterKey
-
public class JceMasterKey extends MasterKey<JceMasterKey>
Represents aMasterKeybacked by one (or more) JCEKeys. Instances of this should only be acquired usinggetInstance(SecretKey, String, String, String)orgetInstance(PublicKey, PrivateKey, String, String, String).
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJceMasterKey(String providerName, String keyId, JceKeyCipher jceKeyCipher)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DataKey<JceMasterKey>decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext)Iterates throughencryptedDataKeysand returns the first one which can be successfully decrypted.DataKey<JceMasterKey>encryptDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext, DataKey<?> dataKey)Returns a new copy of the provideddataKeywhich is protected by thisMasterKeyfor use withalgorithmand associated with the providedencryptionContext.DataKey<JceMasterKey>generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)static JceMasterKeygetInstance(PublicKey wrappingKey, PrivateKey unwrappingKey, String provider, String keyId, String wrappingAlgorithm)Returns aJceMasterKeybacked byunwrappingKeyandwrappingKeyusingwrappingAlgorithm.static JceMasterKeygetInstance(SecretKey key, String provider, String keyId, String wrappingAlgorithm)Returns aJceMasterKeybacked bykeyusingwrappingAlgorithm.StringgetKeyId()StringgetProviderId()-
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
-
-
-
-
Constructor Detail
-
JceMasterKey
protected JceMasterKey(String providerName, String keyId, JceKeyCipher jceKeyCipher)
-
-
Method Detail
-
getInstance
public static JceMasterKey getInstance(SecretKey key, String provider, String keyId, String wrappingAlgorithm)
Returns aJceMasterKeybacked bykeyusingwrappingAlgorithm. Currently "AES/GCM/NoPadding" is the only supported value forwrappingAlgorithm.- Parameters:
key- key used to wrap/unwrap (encrypt/decrypt)DataKeysprovider-keyId-wrappingAlgorithm-- Returns:
-
getInstance
public static JceMasterKey getInstance(PublicKey wrappingKey, PrivateKey unwrappingKey, String provider, String keyId, String wrappingAlgorithm)
Returns aJceMasterKeybacked byunwrappingKeyandwrappingKeyusingwrappingAlgorithm. Currently only RSA algorithms are supported forwrappingAlgorithm.wrappingAlgorithm. IfunwrappingKeyisnullthen the returnedJceMasterKeycan only be used for encryption.
-
getProviderId
public String getProviderId()
- Specified by:
getProviderIdin classMasterKey<JceMasterKey>
-
getKeyId
public String getKeyId()
- Specified by:
getKeyIdin classMasterKey<JceMasterKey>
-
generateDataKey
public DataKey<JceMasterKey> generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)
Description copied from class:MasterKeyGenerates a newDataKeywhich is protected by thisMasterKeyfor use withalgorithmand associated with the providedencryptionContext.- Specified by:
generateDataKeyin classMasterKey<JceMasterKey>
-
encryptDataKey
public DataKey<JceMasterKey> encryptDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext, DataKey<?> dataKey)
Description copied from class:MasterKeyReturns a new copy of the provideddataKeywhich is protected by thisMasterKeyfor use withalgorithmand associated with the providedencryptionContext.- Specified by:
encryptDataKeyin classMasterKey<JceMasterKey>
-
decryptDataKey
public DataKey<JceMasterKey> decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext) throws UnsupportedProviderException, AwsCryptoException
Description copied from class:MasterKeyProviderIterates throughencryptedDataKeysand returns the first one which can be successfully decrypted.- 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
-
-