public class EncryptionHandler extends Object implements MessageCryptoHandler
This class creates the ciphertext headers and delegates the encryption of the plaintext to the
BlockEncryptionHandler
or FrameEncryptionHandler
based on the content type.
Constructor and Description |
---|
EncryptionHandler(int frameSize,
EncryptionMaterials result,
CommitmentPolicy commitmentPolicy)
Create an encryption handler using the provided master key and encryption context.
|
Modifier and Type | Method and Description |
---|---|
int |
doFinal(byte[] out,
int outOff)
Finish encryption of the plaintext bytes.
|
int |
estimateFinalOutputSize()
Return the size of the output buffer required for a call to
CryptoHandler.doFinal(byte[], int) . |
int |
estimateOutputSize(int inLen)
Return the size of the output buffer required for a
processBytes plus a doFinal
with an input of inLen bytes. |
int |
estimatePartialOutputSize(int inLen)
Return the size of the output buffer required for a call to
CryptoHandler.processBytes(byte[], int,
int, byte[], int) . |
Map<String,String> |
getEncryptionContext()
Return the encryption context.
|
CiphertextHeaders |
getHeaders() |
List<? extends MasterKey<?>> |
getMasterKeys()
All used
MasterKey s. |
boolean |
isComplete()
For decrypt and parsing flows returns
true when this has handled as many bytes as it
can. |
ProcessingSummary |
processBytes(byte[] in,
int off,
int len,
byte[] out,
int outOff)
Encrypt a block of bytes from
in putting the plaintext result into out . |
void |
setMaxInputLength(long size)
Informs this handler of an upper bound on the input data size.
|
public EncryptionHandler(int frameSize, EncryptionMaterials result, CommitmentPolicy commitmentPolicy) throws AwsCryptoException
frameSize
- The encryption frame size, or zero for a one-shot encryption taskresult
- The EncryptionMaterials with the crypto materials for this encryption jobAwsCryptoException
- if the encryption context or master key is null.public ProcessingSummary processBytes(byte[] in, int off, int len, byte[] out, int outOff) throws AwsCryptoException, BadCiphertextException
in
putting the plaintext result into out
.
It encrypts by performing the following operations:
processBytes
in interface CryptoHandler
in
- the input byte array.off
- the offset into the in array where the data to be encrypted starts.len
- the number of bytes to be encrypted.out
- the output buffer the encrypted bytes go into.outOff
- the offset into the output byte array the encrypted data starts at.AwsCryptoException
- if len or offset values are negative.BadCiphertextException
- thrown by the underlying cipher handler.public int doFinal(byte[] out, int outOff) throws BadCiphertextException
doFinal
in interface CryptoHandler
out
- space for any resulting output data.outOff
- offset into out to start copying the data at.BadCiphertextException
- thrown by the underlying cipher handler.public int estimateOutputSize(int inLen)
processBytes
plus a doFinal
with an input of inLen bytes.estimateOutputSize
in interface CryptoHandler
inLen
- the length of the input.public int estimatePartialOutputSize(int inLen)
CryptoHandler
CryptoHandler.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.
estimatePartialOutputSize
in interface CryptoHandler
inLen
- the length of the input.CryptoHandler.processBytes(byte[], int, int,
byte[], int)
with an input of size inLen
bytes.public int estimateFinalOutputSize()
CryptoHandler
CryptoHandler.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.
estimateFinalOutputSize
in interface CryptoHandler
CryptoHandler.doFinal(byte[], int)
public Map<String,String> getEncryptionContext()
getEncryptionContext
in interface MessageCryptoHandler
public CiphertextHeaders getHeaders()
getHeaders
in interface MessageCryptoHandler
public void setMaxInputLength(long size)
MessageCryptoHandler
If this method is called multiple times, the smallest bound will be used.
setMaxInputLength
in interface MessageCryptoHandler
size
- An upper bound on the input data size.public List<? extends MasterKey<?>> getMasterKeys()
MessageCryptoHandler
MasterKey
s. For encryption flows, these are all the MasterKey
s used to protect the data. In the decryption flow, it is the single MasterKey
actually used to decrypt the data.getMasterKeys
in interface MessageCryptoHandler
public boolean isComplete()
CryptoHandler
true
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.isComplete
in interface CryptoHandler
Copyright © 2023. All rights reserved.