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.intdoFinal(byte[] out, int outOff)Finish processing of the bytes.intReturn the size of the output buffer required for a call toCryptoHandler.doFinal(byte[], int).intestimateOutputSize(int inLen)Return the size of the output buffer required for aprocessBytesplus adoFinalwith an input of inLen bytes.intestimatePartialOutputSize(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 usedMasterKeys.booleanFor decrypt and parsing flows returnstruewhen 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 ininand copy the plaintext bytes toout.voidsetMaxInputLength(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 ininand copy the plaintext bytes toout.This method consumes and parses the ciphertext headers. The decryption of the actual content is delegated to
BlockDecryptionHandlerorFrameDecryptionHandlerbased on the content type parsed in the ciphertext header.- Specified by:
processBytesin 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
outand 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:
doFinalin interfaceCryptoHandler- Parameters:
out- space for any resulting output data.outOff- offset intooutto 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 aprocessBytesplus adoFinalwith an input of inLen bytes.- Specified by:
estimateOutputSizein interfaceCryptoHandler- Parameters:
inLen- the length of the input.- Returns:
- the space required to accommodate a call to processBytes and doFinal with input of size
inLenbytes.
-
estimatePartialOutputSize
public int estimatePartialOutputSize(int inLen)Description copied from interface:CryptoHandlerReturn 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:
estimatePartialOutputSizein 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 sizeinLenbytes.
-
estimateFinalOutputSize
public int estimateFinalOutputSize()Description copied from interface:CryptoHandlerReturn 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:
estimateFinalOutputSizein 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:
getEncryptionContextin interfaceMessageCryptoHandler- Returns:
- the key-value map containing the encryption client.
-
setMaxInputLength
public void setMaxInputLength(long size)Description copied from interface:MessageCryptoHandlerInforms 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:
setMaxInputLengthin interfaceMessageCryptoHandler- Parameters:
size- An upper bound on the input data size.
-
getHeaders
- Specified by:
getHeadersin interfaceMessageCryptoHandler
-
getMasterKeys
Description copied from interface:MessageCryptoHandlerAll usedMasterKeys. For encryption flows, these are all theMasterKeys used to protect the data. In the decryption flow, it is the singleMasterKeyactually used to decrypt the data.- Specified by:
getMasterKeysin interfaceMessageCryptoHandler
-
isComplete
public boolean isComplete()Description copied from interface:CryptoHandlerFor decrypt and parsing flows returnstruewhen 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:
isCompletein interfaceCryptoHandler
-