Class DecryptionHandler<K extends MasterKey<K>>
- All Implemented Interfaces:
CryptoHandler
,MessageCryptoHandler
EncryptionHandler
.
This class reads and parses the values in the ciphertext headers and delegates the decryption
of the ciphertext to the BlockDecryptionHandler
or FrameDecryptionHandler
based
on the content type parsed in the ciphertext headers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DecryptionHandler<?>
create(CryptoMaterialsManager materialsManager, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys)
Create a decryption handler using the provided materials manager.static DecryptionHandler<?>
create(CryptoMaterialsManager materialsManager, CiphertextHeaders headers, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys)
Deprecated.This version may have to recalculate the number of bytes already parsed, which adds a performance penalty.static DecryptionHandler<?>
create(CryptoMaterialsManager materialsManager, ParsedCiphertext headers, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys)
Create a decryption handler using the provided materials manager and already parsedheaders
.static <K extends MasterKey<K>>
DecryptionHandler<K>create(MasterKeyProvider<K> customerMasterKeyProvider, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys)
Create a decryption handler using the provided master key.static <K extends MasterKey<K>>
DecryptionHandler<K>create(MasterKeyProvider<K> customerMasterKeyProvider, CiphertextHeaders headers, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys)
Deprecated.This version may have to recalculate the number of bytes already parsed, which adds a performance penalty.static <K extends MasterKey<K>>
DecryptionHandler<K>create(MasterKeyProvider<K> customerMasterKeyProvider, ParsedCiphertext headers, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys)
Create a decryption handler using the provided master key and already parsedheaders
.int
doFinal(byte[] out, int outOff)
Finish processing of the bytes.int
Return the size of the output buffer required for a call toCryptoHandler.doFinal(byte[], int)
.int
estimateOutputSize(int inLen)
Return the size of the output buffer required for aprocessBytes
plus adoFinal
with an input of inLen bytes.int
estimatePartialOutputSize(int inLen)
Return the size of the output buffer required for a call toCryptoHandler.processBytes(byte[], int, int, byte[], int)
.Return the encryption context.All usedMasterKey
s.boolean
For decrypt and parsing flows returnstrue
when this has handled as many bytes as it can.processBytes(byte[] in, int off, int len, byte[] out, int outOff)
Decrypt the ciphertext bytes provided inin
and copy the plaintext bytes toout
.void
setMaxInputLength(long size)
Informs this handler of an upper bound on the input data size.
-
Method Details
-
create
public static <K extends MasterKey<K>> DecryptionHandler<K> create(MasterKeyProvider<K> customerMasterKeyProvider, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys) throws AwsCryptoExceptionCreate a decryption handler using the provided master key.Note the methods in the provided master key are used in decrypting the encrypted data key parsed from the ciphertext headers.
- Parameters:
customerMasterKeyProvider
- the master key provider to use in picking a master key from the key blobs encoded in the provided ciphertext.commitmentPolicy
- The commitment policy to enforce during decryptionsignaturePolicy
- The signature policy to enforce during decryptionmaxEncryptedDataKeys
- The maximum number of encrypted data keys to unwrap during decryption; zero indicates no maximum- Throws:
AwsCryptoException
- if the master key is null.
-
create
@Deprecated public static <K extends MasterKey<K>> DecryptionHandler<K> create(MasterKeyProvider<K> customerMasterKeyProvider, CiphertextHeaders headers, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys) throws AwsCryptoExceptionDeprecated.This version may have to recalculate the number of bytes already parsed, which adds a performance penalty. Usecreate(CryptoMaterialsManager, ParsedCiphertext, CommitmentPolicy, SignaturePolicy, int)
instead, which makes the parsed byte count directly available instead.Create a decryption handler using the provided master key and already parsedheaders
.Note the methods in the provided master key are used in decrypting the encrypted data key parsed from the ciphertext headers.
- Parameters:
customerMasterKeyProvider
- the master key provider to use in picking a master key from the key blobs encoded in the provided ciphertext.headers
- already parsed headers which will not be passed intoprocessBytes(byte[], int, int, byte[], int)
commitmentPolicy
- The commitment policy to enforce during decryptionsignaturePolicy
- The signature policy to enforce during decryptionmaxEncryptedDataKeys
- The maximum number of encrypted data keys to unwrap during decryption; zero indicates no maximum- Throws:
AwsCryptoException
- if the master key is null.
-
create
public static <K extends MasterKey<K>> DecryptionHandler<K> create(MasterKeyProvider<K> customerMasterKeyProvider, ParsedCiphertext headers, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys) throws AwsCryptoExceptionCreate a decryption handler using the provided master key and already parsedheaders
.Note the methods in the provided master key are used in decrypting the encrypted data key parsed from the ciphertext headers.
- Parameters:
customerMasterKeyProvider
- the master key provider to use in picking a master key from the key blobs encoded in the provided ciphertext.headers
- already parsed headers which will not be passed intoprocessBytes(byte[], int, int, byte[], int)
commitmentPolicy
- The commitment policy to enforce during decryptionsignaturePolicy
- The signature policy to enforce during decryptionmaxEncryptedDataKeys
- The maximum number of encrypted data keys to unwrap during decryption; zero indicates no maximum- Throws:
AwsCryptoException
- if the master key is null.
-
create
public static DecryptionHandler<?> create(CryptoMaterialsManager materialsManager, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys) throws AwsCryptoExceptionCreate a decryption handler using the provided materials manager.Note the methods in the provided materials manager are used in decrypting the encrypted data key parsed from the ciphertext headers.
- Parameters:
materialsManager
- the materials manager to use in decrypting the data key from the key blobs encoded in the provided ciphertext.commitmentPolicy
- The commitment policy to enforce during decryptionsignaturePolicy
- The signature policy to enforce during decryptionmaxEncryptedDataKeys
- The maximum number of encrypted data keys to unwrap during decryption; zero indicates no maximum- Throws:
AwsCryptoException
- if the master key is null.
-
create
@Deprecated public static DecryptionHandler<?> create(CryptoMaterialsManager materialsManager, CiphertextHeaders headers, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys) throws AwsCryptoExceptionDeprecated.This version may have to recalculate the number of bytes already parsed, which adds a performance penalty. Usecreate(CryptoMaterialsManager, ParsedCiphertext, CommitmentPolicy, SignaturePolicy, int)
instead, which makes the parsed byte count directly available instead.Create a decryption handler using the provided materials manager and already parsedheaders
.Note the methods in the provided materials manager are used in decrypting the encrypted data key parsed from the ciphertext headers.
- Parameters:
materialsManager
- the materials manager to use in decrypting the data key from the key blobs encoded in the provided ciphertext.headers
- already parsed headers which will not be passed intoprocessBytes(byte[], int, int, byte[], int)
commitmentPolicy
- The commitment policy to enforce during decryptionsignaturePolicy
- The signature policy to enforce during decryptionmaxEncryptedDataKeys
- The maximum number of encrypted data keys to unwrap during decryption; zero indicates no maximum- Throws:
AwsCryptoException
- if the master key is null.
-
create
public static DecryptionHandler<?> create(CryptoMaterialsManager materialsManager, ParsedCiphertext headers, CommitmentPolicy commitmentPolicy, SignaturePolicy signaturePolicy, int maxEncryptedDataKeys) throws AwsCryptoExceptionCreate a decryption handler using the provided materials manager and already parsedheaders
.Note the methods in the provided materials manager are used in decrypting the encrypted data key parsed from the ciphertext headers.
- Parameters:
materialsManager
- the materials manager to use in decrypting the data key from the key blobs encoded in the provided ciphertext.headers
- already parsed headers which will not be passed intoprocessBytes(byte[], int, int, byte[], int)
commitmentPolicy
- The commitment policy to enforce during decryptionsignaturePolicy
- The signature policy to enforce during decryptionmaxEncryptedDataKeys
- The maximum number of encrypted data keys to unwrap during decryption; zero indicates no maximum- Throws:
AwsCryptoException
- if the master key is null.
-
processBytes
public ProcessingSummary processBytes(byte[] in, int off, int len, byte[] out, int outOff) throws BadCiphertextException, AwsCryptoExceptionDecrypt the ciphertext bytes provided inin
and copy the plaintext bytes toout
.This method consumes and parses the ciphertext headers. The decryption of the actual content is delegated to
BlockDecryptionHandler
orFrameDecryptionHandler
based on the content type parsed in the ciphertext header.- Specified by:
processBytes
in interfaceCryptoHandler
- Parameters:
in
- the input byte array.off
- the offset into the in array where the data to be decrypted starts.len
- the number of bytes to be decrypted.out
- the output buffer the decrypted plaintext bytes go into.outOff
- the offset into the output byte array the decrypted data starts at.- Returns:
- the number of bytes written to
out
and processed. - Throws:
BadCiphertextException
- if the ciphertext header contains invalid entries or if the header integrity check fails.AwsCryptoException
- if any of the offset or length arguments are negative or if the total bytes to decrypt exceeds the maximum allowed value.
-
doFinal
Finish processing of the bytes.- Specified by:
doFinal
in interfaceCryptoHandler
- Parameters:
out
- space for any resulting output data.outOff
- offset intoout
to start copying the data at.- Returns:
- number of bytes written into
out
. - Throws:
BadCiphertextException
- if the bytes do not decrypt correctly.
-
estimateOutputSize
public int estimateOutputSize(int inLen)Return the size of the output buffer required for aprocessBytes
plus adoFinal
with an input of inLen bytes.- Specified by:
estimateOutputSize
in interfaceCryptoHandler
- Parameters:
inLen
- the length of the input.- Returns:
- the space required to accommodate a call to processBytes and doFinal with input of size
inLen
bytes.
-
estimatePartialOutputSize
public int estimatePartialOutputSize(int inLen)Description copied from interface:CryptoHandler
Return the size of the output buffer required for a call toCryptoHandler.processBytes(byte[], int, int, byte[], int)
.Note this method is allowed to return an estimation of the output size that is greater than the actual size of the output. Returning an estimate that is lesser than the actual size of the output will result in underflow exceptions.
- Specified by:
estimatePartialOutputSize
in interfaceCryptoHandler
- Parameters:
inLen
- the length of the input.- Returns:
- the space required to accommodate a call to
CryptoHandler.processBytes(byte[], int, int, byte[], int)
with an input of sizeinLen
bytes.
-
estimateFinalOutputSize
public int estimateFinalOutputSize()Description copied from interface:CryptoHandler
Return the size of the output buffer required for a call toCryptoHandler.doFinal(byte[], int)
.Note this method is allowed to return an estimation of the output size that is greater than the actual size of the output. Returning an estimate that is lesser than the actual size of the output will result in underflow exceptions.
- Specified by:
estimateFinalOutputSize
in interfaceCryptoHandler
- Returns:
- the space required to accomodate a call to
CryptoHandler.doFinal(byte[], int)
-
getEncryptionContext
Return the encryption context. This value is parsed from the ciphertext.- Specified by:
getEncryptionContext
in interfaceMessageCryptoHandler
- Returns:
- the key-value map containing the encryption client.
-
setMaxInputLength
public void setMaxInputLength(long size)Description copied from interface:MessageCryptoHandler
Informs this handler of an upper bound on the input data size. The handler will throw an exception if this bound is exceeded, and may use it to perform performance optimizations as well.If this method is called multiple times, the smallest bound will be used.
- Specified by:
setMaxInputLength
in interfaceMessageCryptoHandler
- Parameters:
size
- An upper bound on the input data size.
-
getHeaders
- Specified by:
getHeaders
in interfaceMessageCryptoHandler
-
getMasterKeys
Description copied from interface:MessageCryptoHandler
All usedMasterKey
s. For encryption flows, these are all theMasterKey
s used to protect the data. In the decryption flow, it is the singleMasterKey
actually used to decrypt the data.- Specified by:
getMasterKeys
in interfaceMessageCryptoHandler
-
isComplete
public boolean isComplete()Description copied from interface:CryptoHandler
For decrypt and parsing flows returnstrue
when this has handled as many bytes as it can. This usually means that it has reached the end of an object, file, or other delimited stream.- Specified by:
isComplete
in interfaceCryptoHandler
-