public class CiphertextHeaders extends Object
See https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html for a detailed description of the fields that make up the encrypted message header.
It is important to note that all but the last two header fields are checked for their integrity during decryption using AES-GCM with the nonce and MAC tag values supplied in the last two fields of the header.
Modifier and Type | Field and Description |
---|---|
static int |
NO_MAX_ENCRYPTED_DATA_KEYS
When passed as maxEncryptedDataKeys, indicates that no maximum should be enforced (i.e., any
number of EDKs are allowed).
|
Constructor and Description |
---|
CiphertextHeaders()
Default constructor.
|
CiphertextHeaders(byte version,
CiphertextType type,
CryptoAlgorithm cryptoAlgo,
byte[] encryptionContext,
List<KeyBlob> keyBlobs,
ContentType contentType,
int frameSize)
|
CiphertextHeaders(CiphertextType type,
CryptoAlgorithm cryptoAlgo,
byte[] encryptionContext,
List<KeyBlob> keyBlobs,
ContentType contentType,
int frameSize)
Construct the ciphertext headers using the provided values.
|
Modifier and Type | Method and Description |
---|---|
int |
deserialize(byte[] b,
int off)
Deserialize the provided bytes starting at the specified offset to construct an instance of
this class.
|
int |
deserialize(byte[] b,
int off,
int maxEncryptedDataKeys)
Deserialize the provided bytes starting at the specified offset to construct an instance of
this class.
|
ContentType |
getContentType()
Return the content type set in the header.
|
CryptoAlgorithm |
getCryptoAlgoId()
Return the crypto algorithm identifier set in the header.
|
int |
getEncryptedKeyBlobCount()
Return the count of the encrypted key blobs set in the header.
|
List<KeyBlob> |
getEncryptedKeyBlobs()
Return the encrypted key blobs set in the header.
|
byte[] |
getEncryptionContext()
Return the encryption context set in the header.
|
int |
getEncryptionContextLen()
Return the length of the encryption context set in the header.
|
Map<String,String> |
getEncryptionContextMap() |
int |
getFrameLength()
Return the length of the frame set in the header.
|
byte[] |
getHeaderNonce()
Return the header nonce set in the header.
|
byte[] |
getHeaderTag()
Return the header tag set in the header.
|
byte[] |
getMessageId()
Return the message identifier set in the header.
|
short |
getNonceLength()
Return the length of the nonce set in the header.
|
byte[] |
getSuiteData()
Return suite specific data.
|
CiphertextType |
getType()
Return the type set in the header.
|
byte |
getVersion()
Return the version set in the header.
|
Boolean |
isComplete()
Check if this object has all the header fields populated and available for reading.
|
byte[] |
serializeAuthenticatedFields()
Serialize the header fields into a byte array.
|
void |
setHeaderNonce(byte[] headerNonce)
Set the header nonce to use for authenticating the header data.
|
void |
setHeaderTag(byte[] headerTag)
Set the header tag to use for authenticating the header data.
|
void |
setSuiteData(byte[] suiteData)
Sets suite specific data
|
byte[] |
toByteArray()
Serialize the header fields into a byte array.
|
public static final int NO_MAX_ENCRYPTED_DATA_KEYS
public CiphertextHeaders()
@Deprecated public CiphertextHeaders(byte version, CiphertextType type, CryptoAlgorithm cryptoAlgo, byte[] encryptionContext, List<KeyBlob> keyBlobs, ContentType contentType, int frameSize)
version
- the version to set in the header.type
- the type to set in the header.cryptoAlgo
- the CryptoAlgorithm enum to encode in the header.encryptionContext
- the bytes containing the encryption context to set in the header.keyBlobs
- list of keyBlobs containing the key provider id, key provider info, and
encrypted data key to encode in the header.contentType
- the content type to set in the header.frameSize
- the frame payload size to set in the header.public CiphertextHeaders(CiphertextType type, CryptoAlgorithm cryptoAlgo, byte[] encryptionContext, List<KeyBlob> keyBlobs, ContentType contentType, int frameSize)
type
- the type to set in the header.cryptoAlgo
- the CryptoAlgorithm enum to encode in the header.encryptionContext
- the bytes containing the encryption context to set in the header.keyBlobs
- list of keyBlobs containing the key provider id, key provider info, and
encrypted data key to encode in the header.contentType
- the content type to set in the header.frameSize
- the frame payload size to set in the header.public Boolean isComplete()
public int deserialize(byte[] b, int off) throws ParseException
This method parses the provided bytes for the individual fields in this class. This method also supports partial parsing where not all the bytes required for parsing the fields successfully are available.
b
- the byte array to deserialize.off
- the offset in the byte array to use for deserialization.ParseException
public int deserialize(byte[] b, int off, int maxEncryptedDataKeys) throws ParseException
This method parses the provided bytes for the individual fields in this class. This method also supports partial parsing where not all the bytes required for parsing the fields successfully are available.
b
- the byte array to deserialize.off
- the offset in the byte array to use for deserialization.maxEncryptedDataKeys
- the maximum number of EDKs to deserialize; zero indicates no
maximumParseException
public byte[] serializeAuthenticatedFields()
public byte[] toByteArray()
public byte getVersion()
public CiphertextType getType()
public CryptoAlgorithm getCryptoAlgoId()
public int getEncryptionContextLen()
public byte[] getEncryptionContext()
public int getEncryptedKeyBlobCount()
public List<KeyBlob> getEncryptedKeyBlobs()
public ContentType getContentType()
public byte[] getMessageId()
public short getNonceLength()
public int getFrameLength()
public byte[] getHeaderNonce()
public byte[] getHeaderTag()
public void setHeaderNonce(byte[] headerNonce)
headerNonce
- the header nonce to use.public void setHeaderTag(byte[] headerTag)
headerTag
- the header tag to use.public byte[] getSuiteData()
public void setSuiteData(byte[] suiteData)
suiteData
- Copyright © 2023. All rights reserved.