public class EncryptionHandler<K extends MasterKey<K>> extends Object implements MessageCryptoHandler<K>
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(List<K> masterKeys,
Map<String,String> encryptionContext,
CryptoAlgorithm cryptoAlgorithm,
int frameSize)
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 |
estimateOutputSize(int inLen)
Return the size of the output buffer required for a
processBytes plus a
doFinal with an input of inLen bytes. |
Map<String,String> |
getEncryptionContext()
Return the encryption context.
|
CiphertextHeaders |
getHeaders() |
List<K> |
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 . |
public EncryptionHandler(List<K> masterKeys, Map<String,String> encryptionContext, CryptoAlgorithm cryptoAlgorithm, int frameSize) throws AwsCryptoException
masterKeys
- the master keys to use.encryptionContext
- the encryption context to use.cryptoAlgorithm
- the cryptography algorithm to use for encryptionframeSize
- the size of the frames to use in storing encrypted contentAwsCryptoException
- 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 Map<String,String> getEncryptionContext()
getEncryptionContext
in interface MessageCryptoHandler<K extends MasterKey<K>>
public CiphertextHeaders getHeaders()
getHeaders
in interface MessageCryptoHandler<K extends MasterKey<K>>
public List<K> 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<K extends MasterKey<K>>
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 deliminited
stream.isComplete
in interface CryptoHandler
Copyright © 2016. All rights reserved.