public class CiphertextHeader extends 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.
Constructor and Description |
---|
CiphertextHeader(byte[] nonce)
Creates a new instance with only a nonce.
|
CiphertextHeader(byte[] nonce,
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(InputStream input)
Creates a header from encrypted data containing a cleartext header prepended to the start.
|
byte[] |
encode()
Encodes the header into bytes.
|
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.
|
public CiphertextHeader(byte[] nonce)
nonce
- Nonce bytes.public CiphertextHeader(byte[] nonce, String keyName)
nonce
- Nonce bytes.keyName
- Key name.public int getLength()
public byte[] getNonce()
public 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(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.Copyright © 2003-2015 Virginia Tech. All Rights Reserved.