Class CiphertextHeader

java.lang.Object
org.cryptacular.CiphertextHeader
Direct Known Subclasses:
CiphertextHeaderV2

@Deprecated public class CiphertextHeader extends Object
Deprecated.
Superseded by CiphertextHeaderV2
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

    Fields
    Modifier and Type
    Field
    Description
    protected 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

    Constructors
    Constructor
    Description
    CiphertextHeader(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 Type
    Method
    Description
    protected int
    Deprecated.
     
    decode(byte[] data)
    Deprecated.
    Creates a header from encrypted data containing a cleartext header prepended to the start.
    Deprecated.
    Creates a header from encrypted data containing a cleartext header prepended to the start.
    byte[]
    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[]
    Deprecated.
    Gets the bytes of the nonce/IV.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_NONCE_LEN

      protected static final int MAX_NONCE_LEN
      Deprecated.
      Maximum nonce length in bytes.
      See Also:
    • MAX_KEYNAME_LEN

      protected static final int MAX_KEYNAME_LEN
      Deprecated.
      Maximum key name length in bytes.
      See Also:
    • nonce

      protected final byte[] nonce
      Deprecated.
      Header nonce field value.
    • keyName

      protected String keyName
      Deprecated.
      Header key name field value.
    • length

      protected int length
      Deprecated.
      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

      public CiphertextHeader(byte[] nonce, String keyName)
      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

      public String 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

      public static CiphertextHeader decode(byte[] data) throws EncodingException
      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

      public static CiphertextHeader decode(InputStream input) throws EncodingException, StreamException
      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.