Class AesSpec
- All Implemented Interfaces:
Describable, ContextSpec
An AesSpec captures compile‑time choices for the AES transform: the
block mode, padding scheme (CBC only), and—when using GCM—the authentication
tag length in bits. It may optionally embed a
SymmetricHeaderCodec that governs how runtime
parameters (IV/nonce, tag bits, AAD hash) are written to and read from the
data stream. No IV/nonce or AAD bytes are stored in this type; those are
runtime values exchanged via a Conflux session context.
Design
- Immutability: instances are immutable and thread‑safe.
- Validation: GCM requires
NOPADDINGand a tag length between 96 and 128 bits (inclusive) in 8‑bit increments; non‑GCM modes must not specify a tag length. - Header codec: when present, the codec persists IV and GCM parameters in‑band, and can bind AAD via a hash. The cipher context hydrates the runtime context from this header during decryption, and writes it during encryption.
- Runtime parameters: IV sizes are dictated by mode (12 bytes for GCM; 16 for CBC/CTR) and are generated or required at runtime by the cipher context, not by this spec.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forAesSpec.static enumAES block modes supported by this implementation.static enumPadding schemes for CBC mode. -
Method Summary
Modifier and TypeMethodDescriptionstatic AesSpec.Builderbuilder()Returns a new builder with safe defaults (AesSpec.Mode.GCM,AesSpec.Padding.NOPADDING, 128‑bit tag, no header).static AesSpeccbcPkcs7(SymmetricHeaderCodec header) Creates a CBC specification using PKCS#7 padding and the provided header.static AesSpecctr(SymmetricHeaderCodec header) Creates a CTR specification with no padding and the provided header.Produces a compact human‑readable description of this specification, such as"AES-GCM(tag=128)"or"AES-CBC/PKCS7Padding".static AesSpecgcm128(SymmetricHeaderCodec header) Creates a GCM specification with a 128‑bit authentication tag and the provided header codec.header()Returns the embedded header codec, if any.mode()Returns the selected AES mode.padding()Returns the selected padding scheme.intReturns the authentication tag length in bits.
-
Method Details
-
builder
Returns a new builder with safe defaults (AesSpec.Mode.GCM,AesSpec.Padding.NOPADDING, 128‑bit tag, no header).- Returns:
- a fresh builder for
AesSpec
-
gcm128
Creates a GCM specification with a 128‑bit authentication tag and the provided header codec.- Parameters:
header- the header codec to embed, ornullfor none- Returns:
- a specification for
AES/GCM/NOPADDINGwith a 128‑bit tag
-
cbcPkcs7
Creates a CBC specification using PKCS#7 padding and the provided header.- Parameters:
header- the header codec to embed, ornullfor none- Returns:
- a specification for
AES/CBC/PKCS7Padding
-
ctr
Creates a CTR specification with no padding and the provided header.- Parameters:
header- the header codec to embed, ornullfor none- Returns:
- a specification for
AES/CTR/NOPADDING
-
mode
Returns the selected AES mode.This value determines IV length expectations and whether AAD and tag length apply (GCM only).
- Returns:
- the block mode used by this specification
-
padding
Returns the selected padding scheme.Relevant only for CBC; GCM and CTR always operate with no padding.
- Returns:
- the padding scheme (never
null)
-
tagLenBits
public int tagLenBits()Returns the authentication tag length in bits.For GCM, this is one of 96, 104, 112, 120, or 128. For non‑GCM modes, this method returns
0.- Returns:
- the GCM tag length in bits, or
0if not applicable
-
header
Returns the embedded header codec, if any.When non‑null, the cipher context writes the header during encryption (after the IV is chosen) and reads it during decryption to hydrate the runtime context.
- Returns:
- the header codec, or
nullif no header is used
-
description
Produces a compact human‑readable description of this specification, such as"AES-GCM(tag=128)"or"AES-CBC/PKCS7Padding".- Specified by:
descriptionin interfaceDescribable- Returns:
- a descriptive string for diagnostics and logs
-