public class CiphertextHeader
extends java.lang.Object
Data format:
+-----+----------+-------+------------+---------+
| Len | NonceLen | Nonce | KeyNameLen | KeyName |
+-----+----------+-------+------------+---------+
Where fields are defined as follows:
The last two fields are optional and provide support for multiple keys at the encryption provider. A common case for multiple keys is key rotation; by tagging encrypted data with a key name, an old key may be retrieved by name to decrypt outstanding data which will be subsequently re-encrypted with a new key.
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
keyName
Header key name field value.
|
private int |
length
Header length in bytes.
|
private byte[] |
nonce
Header nonce field value.
|
| Constructor and Description |
|---|
CiphertextHeader(byte[] nonce)
Creates a new instance with only a nonce.
|
CiphertextHeader(byte[] nonce,
java.lang.String keyName)
Creates a new instance with a nonce and named key.
|
| Modifier and Type | Method and Description |
|---|---|
static CiphertextHeader |
decode(byte[] data)
Creates a header from encrypted data containing a cleartext header prepended to the start.
|
static CiphertextHeader |
decode(java.io.InputStream input)
Creates a header from encrypted data containing a cleartext header prepended to the start.
|
byte[] |
encode()
Encodes the header into bytes.
|
java.lang.String |
getKeyName()
Gets the encryption key name stored in the header.
|
int |
getLength()
Gets the header length in bytes.
|
byte[] |
getNonce()
Gets the bytes of the nonce/IV.
|
private final byte[] nonce
private java.lang.String keyName
private int length
public CiphertextHeader(byte[] nonce)
nonce - Nonce bytes.public CiphertextHeader(byte[] nonce,
java.lang.String keyName)
nonce - Nonce bytes.keyName - Key name.public int getLength()
public byte[] getNonce()
public java.lang.String getKeyName()
public byte[] encode()
public static CiphertextHeader decode(byte[] data) throws EncodingException
data - Encrypted data with prepended header data.EncodingException - when ciphertext header cannot be decoded.public static CiphertextHeader decode(java.io.InputStream input) throws EncodingException, StreamException
input - Input stream that is positioned at the start of ciphertext header data.EncodingException - when ciphertext header cannot be decoded.StreamException - on stream IO errors.