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 abstract class JceMasterKey extends MasterKey<JceMasterKey>
Represents aMasterKey
backed by one (or more) JCEKey
s. Instances of this should only be acquired usinggetInstance(SecretKey, String, String, String)
orgetInstance(PublicKey, PrivateKey, String, String, String)
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JceMasterKey(Key wrappingKey, Key unwrappingKey, String providerName, String keyId)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected DataKey<JceMasterKey>
actualDecrypt(CryptoAlgorithm algorithm, EncryptedDataKey edk, Map<String,String> encryptionContext)
protected static boolean
arrayPrefixEquals(byte[] a, byte[] b, int len)
protected abstract Cipher
buildUnwrappingCipher(Key key, byte[] extraInfo, int offset, Map<String,String> encryptionContext)
protected abstract com.amazonaws.encryptionsdk.jce.JceMasterKey.WrappingData
buildWrappingCipher(Key key, Map<String,String> encryptionContext)
DataKey<JceMasterKey>
decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext)
Iterates throughencryptedDataKeys
and 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 provideddataKey
which is protected by thisMasterKey
for use withalgorithm
and associated with the providedencryptionContext
.protected DataKey<JceMasterKey>
encryptRawKey(SecretKey key, byte[] rawKey, Map<String,String> encryptionContext)
DataKey<JceMasterKey>
generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)
static JceMasterKey
getInstance(PublicKey wrappingKey, PrivateKey unwrappingKey, String provider, String keyId, String wrappingAlgorithm)
Returns aJceMasterKey
backed byunwrappingKey
andwrappingKey
usingwrappingAlgorithm
.static JceMasterKey
getInstance(SecretKey key, String provider, String keyId, String wrappingAlgorithm)
Returns aJceMasterKey
backed bykey
usingwrappingAlgorithm
.String
getKeyId()
String
getProviderId()
-
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
public static JceMasterKey getInstance(SecretKey key, String provider, String keyId, String wrappingAlgorithm)
Returns aJceMasterKey
backed bykey
usingwrappingAlgorithm
. Currently "AES/GCM/NoPadding
" is the only supported value forwrappingAlgorithm
.- Parameters:
key
- key used to wrap/unwrap (encrypt/decrypt)DataKey
sprovider
-keyId
-wrappingAlgorithm
-- Returns:
-
getInstance
public static JceMasterKey getInstance(PublicKey wrappingKey, PrivateKey unwrappingKey, String provider, String keyId, String wrappingAlgorithm)
Returns aJceMasterKey
backed byunwrappingKey
andwrappingKey
usingwrappingAlgorithm
. Currently only RSA algorithms are supported forwrappingAlgorithm
.wrappingAlgorithm
. IfunwrappingKey
isnull
then the returnedJceMasterKey
can only be used for encryption.
-
getProviderId
public String getProviderId()
- Specified by:
getProviderId
in classMasterKey<JceMasterKey>
-
getKeyId
public String getKeyId()
- Specified by:
getKeyId
in classMasterKey<JceMasterKey>
-
generateDataKey
public DataKey<JceMasterKey> 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<JceMasterKey>
-
encryptDataKey
public DataKey<JceMasterKey> 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<JceMasterKey>
-
encryptRawKey
protected DataKey<JceMasterKey> encryptRawKey(SecretKey key, byte[] rawKey, Map<String,String> encryptionContext)
-
decryptDataKey
public DataKey<JceMasterKey> 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<JceMasterKey>
- 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
-
actualDecrypt
protected DataKey<JceMasterKey> actualDecrypt(CryptoAlgorithm algorithm, EncryptedDataKey edk, Map<String,String> encryptionContext) throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
arrayPrefixEquals
protected static boolean arrayPrefixEquals(byte[] a, byte[] b, int len)
-
buildWrappingCipher
protected abstract com.amazonaws.encryptionsdk.jce.JceMasterKey.WrappingData buildWrappingCipher(Key key, Map<String,String> encryptionContext) throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
buildUnwrappingCipher
protected abstract Cipher buildUnwrappingCipher(Key key, byte[] extraInfo, int offset, Map<String,String> encryptionContext) throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
-