Class AesHeaderCodec
java.lang.Object
zeroecho.core.alg.aes.AesHeaderCodec
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionreadHeader(InputStream in, CryptoAlgorithm algorithm, CtxInterface ctx) Reads a header fromin, updates the context with IV (and tag bits), and verifies AAD if present.voidwriteHeader(OutputStream out, CryptoAlgorithm algorithm, CtxInterface ctx) Writes the header tooutusing values from the provided context.
-
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 tooutusing values from the provided context.- Specified by:
writeHeaderin interfaceSymmetricHeaderCodec- Parameters:
out- destination streamalgorithm- 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 fromin, updates the context with IV (and tag bits), and verifies AAD if present.- Specified by:
readHeaderin interfaceSymmetricHeaderCodec- Parameters:
in- source stream positioned at headeralgorithm- 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
-