Package org.cryptacular
Class CiphertextHeader
java.lang.Object
org.cryptacular.CiphertextHeader
- Direct Known Subclasses:
CiphertextHeaderV2
Deprecated.
Cleartext header prepended to ciphertext providing data required for decryption.
Data format:
+-----+----------+-------+------------+---------+ | Len | NonceLen | Nonce | KeyNameLen | KeyName | +-----+----------+-------+------------+---------+
Where fields are defined as follows:
- Len - Total header length in bytes (4-byte integer)
- NonceLen - Nonce length in bytes (4-byte integer)
- Nonce - Nonce bytes (variable length)
- KeyNameLen (OPTIONAL) - Key name length in bytes (4-byte integer)
- KeyName (OPTIONAL) - Key name encoded as bytes in platform-specific encoding (variable length)
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.
- Author:
- Middleware Services
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
Deprecated.Header key name field value.protected int
Deprecated.Header length in bytes.protected static final int
Deprecated.Maximum key name length in bytes.protected static final int
Deprecated.Maximum nonce length in bytes.protected final byte[]
Deprecated.Header nonce field value. -
Constructor Summary
ConstructorsConstructorDescriptionCiphertextHeader
(byte[] nonce) Deprecated.Creates a new instance with only a nonce.CiphertextHeader
(byte[] nonce, String keyName) Deprecated.Creates a new instance with a nonce and named key. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Deprecated.static CiphertextHeader
decode
(byte[] data) Deprecated.Creates a header from encrypted data containing a cleartext header prepended to the start.static CiphertextHeader
decode
(InputStream input) Deprecated.Creates a header from encrypted data containing a cleartext header prepended to the start.byte[]
encode()
Deprecated.Encodes the header into bytes.Deprecated.Gets the encryption key name stored in the header.int
Deprecated.Gets the header length in bytes.byte[]
getNonce()
Deprecated.Gets the bytes of the nonce/IV.
-
Field Details
-
MAX_NONCE_LEN
protected static final int MAX_NONCE_LENDeprecated.Maximum nonce length in bytes.- See Also:
-
MAX_KEYNAME_LEN
protected static final int MAX_KEYNAME_LENDeprecated.Maximum key name length in bytes.- See Also:
-
nonce
protected final byte[] nonceDeprecated.Header nonce field value. -
keyName
Deprecated.Header key name field value. -
length
protected int lengthDeprecated.Header length in bytes.
-
-
Constructor Details
-
CiphertextHeader
public CiphertextHeader(byte[] nonce) Deprecated.Creates a new instance with only a nonce.- Parameters:
nonce
- Nonce bytes.
-
CiphertextHeader
Deprecated.Creates a new instance with a nonce and named key.- Parameters:
nonce
- Nonce bytes.keyName
- Key name.
-
-
Method Details
-
getLength
public int getLength()Deprecated.Gets the header length in bytes.- Returns:
- Header length in bytes.
-
getNonce
public byte[] getNonce()Deprecated.Gets the bytes of the nonce/IV.- Returns:
- Nonce bytes.
-
getKeyName
Deprecated.Gets the encryption key name stored in the header.- Returns:
- Encryption key name.
-
encode
public byte[] encode()Deprecated.Encodes the header into bytes.- Returns:
- Byte representation of header.
-
computeLength
protected int computeLength()Deprecated.- Returns:
- Length of this header encoded as bytes.
-
decode
Deprecated.Creates a header from encrypted data containing a cleartext header prepended to the start.- Parameters:
data
- Encrypted data with prepended header data.- Returns:
- Decoded header.
- Throws:
EncodingException
- when ciphertext header cannot be decoded.
-
decode
Deprecated.Creates a header from encrypted data containing a cleartext header prepended to the start.- Parameters:
input
- Input stream that is positioned at the start of ciphertext header data.- Returns:
- Decoded header.
- Throws:
EncodingException
- when ciphertext header cannot be decoded.StreamException
- on stream IO errors.
-
CiphertextHeaderV2