Class AesHeaderCodec

java.lang.Object
zeroecho.core.alg.aes.AesHeaderCodec
All Implemented Interfaces:
SymmetricHeaderCodec

public final class AesHeaderCodec extends Object implements SymmetricHeaderCodec
Minimal AES header codec that persists runtime parameters only:
IV | tagBits(pack7) | aadFlag(1) | [aadHash(32)]
  • IV: 12 bytes for GCM; 16 bytes for CBC/CTR.
  • tagBits: 0 for non‑GCM; otherwise 96..128.
  • aadFlag: 1 when AAD is present; the header then includes a SHA‑256 of the AAD.

No algorithm magic is written. On decrypt, the codec hydrates the Conflux context with IV and tag bits and enforces AAD consistency if an AAD hash is present.

Since:
1.0
  • Constructor Details

    • AesHeaderCodec

      public AesHeaderCodec()
      Creates a stateless AES stream-header codec.
  • Method Details

    • writeHeader

      public void writeHeader(OutputStream out, CryptoAlgorithm algorithm, CtxInterface ctx) throws IOException
      Writes the header to out using values from the provided context.
      Specified by:
      writeHeader in interface SymmetricHeaderCodec
      Parameters:
      out - destination stream
      algorithm - owning algorithm (ID "AES")
      ctx - source of IV, optional tag bits, and optional AAD
      Throws:
      IOException - if IV is missing or an I/O error occurs
    • readHeader

      public InputStream readHeader(InputStream in, CryptoAlgorithm algorithm, CtxInterface ctx) throws IOException
      Reads a header from in, updates the context with IV (and tag bits), and verifies AAD if present.
      Specified by:
      readHeader in interface SymmetricHeaderCodec
      Parameters:
      in - source stream positioned at header
      algorithm - owning algorithm (ID "AES")
      ctx - destination for IV/tag bits and AAD verification
      Returns:
      the same InputStream, positioned after the header
      Throws:
      IOException - on malformed header, missing AAD when required, or AAD hash mismatch