public abstract class JceMasterKey extends MasterKey<JceMasterKey>
MasterKey
backed by one (or more) JCE Key
s. Instances of this should
only be acquired using getInstance(SecretKey, String, String, String)
or
getInstance(PublicKey, PrivateKey, String, String, String)
.Modifier | Constructor and Description |
---|---|
protected |
JceMasterKey(Key wrappingKey,
Key unwrappingKey,
String providerName,
String keyId) |
Modifier and Type | Method and 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 through
encryptedDataKeys 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 provided
dataKey which is protected by this
MasterKey for use with algorithm and associated with the provided
encryptionContext . |
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 a
JceMasterKey backed by unwrappingKey and wrappingKey using
wrappingAlgorithm . |
static JceMasterKey |
getInstance(SecretKey key,
String provider,
String keyId,
String wrappingAlgorithm)
Returns a
JceMasterKey backed by key using wrappingAlgorithm . |
String |
getKeyId() |
String |
getProviderId() |
canProvide, equals, getDefaultProviderId, getMasterKey, getMasterKeysForEncryption, hashCode, toString
buildCannotDecryptDksException, buildCannotDecryptDksException, buildCannotDecryptDksException, getMasterKey
public static JceMasterKey getInstance(SecretKey key, String provider, String keyId, String wrappingAlgorithm)
JceMasterKey
backed by key
using wrappingAlgorithm
.
Currently "AES/GCM/NoPadding
" is the only supported value for
wrappingAlgorithm
.key
- key used to wrap/unwrap (encrypt/decrypt) DataKey
sprovider
- keyId
- wrappingAlgorithm
- public static JceMasterKey getInstance(PublicKey wrappingKey, PrivateKey unwrappingKey, String provider, String keyId, String wrappingAlgorithm)
JceMasterKey
backed by unwrappingKey
and wrappingKey
using
wrappingAlgorithm
. Currently only RSA algorithms are supported for
wrappingAlgorithm
. wrappingAlgorithm
. If unwrappingKey
is
null
then the returned JceMasterKey
can only be used for encryption.public String getProviderId()
getProviderId
in class MasterKey<JceMasterKey>
public String getKeyId()
getKeyId
in class MasterKey<JceMasterKey>
public DataKey<JceMasterKey> generateDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext)
MasterKey
DataKey
which is protected by this MasterKey
for use with
algorithm
and associated with the provided encryptionContext
.generateDataKey
in class MasterKey<JceMasterKey>
public DataKey<JceMasterKey> encryptDataKey(CryptoAlgorithm algorithm, Map<String,String> encryptionContext, DataKey<?> dataKey)
MasterKey
dataKey
which is protected by this
MasterKey
for use with algorithm
and associated with the provided
encryptionContext
.encryptDataKey
in class MasterKey<JceMasterKey>
protected DataKey<JceMasterKey> encryptRawKey(SecretKey key, byte[] rawKey, Map<String,String> encryptionContext)
public DataKey<JceMasterKey> decryptDataKey(CryptoAlgorithm algorithm, Collection<? extends EncryptedDataKey> encryptedDataKeys, Map<String,String> encryptionContext) throws UnsupportedProviderException, AwsCryptoException
MasterKeyProvider
encryptedDataKeys
and returns the first one which can be
successfully decrypted.decryptDataKey
in class MasterKeyProvider<JceMasterKey>
null
UnsupportedProviderException
- if the encryptedDataKey
is associated with an unsupported providerCannotUnwrapDataKeyException
- if the encryptedDataKey
cannot be decryptedAwsCryptoException
protected DataKey<JceMasterKey> actualDecrypt(CryptoAlgorithm algorithm, EncryptedDataKey edk, Map<String,String> encryptionContext) throws GeneralSecurityException
GeneralSecurityException
protected static boolean arrayPrefixEquals(byte[] a, byte[] b, int len)
protected abstract com.amazonaws.encryptionsdk.jce.JceMasterKey.WrappingData buildWrappingCipher(Key key, Map<String,String> encryptionContext) throws GeneralSecurityException
GeneralSecurityException
protected abstract Cipher buildUnwrappingCipher(Key key, byte[] extraInfo, int offset, Map<String,String> encryptionContext) throws GeneralSecurityException
GeneralSecurityException
Copyright © 2016. All rights reserved.