Class AesCipherContext
- All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, EncryptionContext, ContextAware
IV and optional AAD are exchanged via a CtxInterface set with
setContext(conflux.CtxInterface). Encryption always generates a
fresh IV after atomically claiming the context; a caller-provided IV is never
used for encryption. Decryption requires the IV from the context or encoded
header.
When a SymmetricHeaderCodec is embedded in the
AesSpec and a context is present, the context reads/writes a minimal
header carrying IV, tag bits, and an optional AAD hash.
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionAesCipherContext(CryptoAlgorithm algorithm, SecretKey key, boolean encrypt, AesSpec spec, SecureRandom rnd) Creates a new AES streaming context. -
Method Summary
Modifier and TypeMethodDescriptionReturns the algorithm descriptor (ID"AES").attach(InputStream upstream) Attaches this context to an upstream stream and returns a transforming stream.voidclose()Completes the context's implementation-specific cleanup.context()Returns the currently set Conflux context (possiblynull).key()Returns the key bound to this context.voidsetContext(CtxInterface context) Sets the Conflux session context used to exchange IV/AAD/tagBits and to enable header I/O.
-
Constructor Details
-
AesCipherContext
public AesCipherContext(CryptoAlgorithm algorithm, SecretKey key, boolean encrypt, AesSpec spec, SecureRandom rnd) Creates a new AES streaming context.- Parameters:
algorithm- the owning algorithm descriptor (ID"AES"); not nullkey- the AESSecretKey; not nullencrypt- whether this context encrypts (true) or decrypts (false)spec- static AES settings (mode/padding and GCM tag bits); not nullrnd- secure random source; if null, the library's shared source is used- Throws:
NullPointerException- if any required parameter is nullIllegalArgumentException- ifspecis inconsistent (e.g., GCM without NOPADDING)
-
-
Method Details
-
algorithm
Returns the algorithm descriptor (ID"AES").- Specified by:
algorithmin interfaceCryptoContext- Returns:
- the algorithm
-
key
Returns the key bound to this context.- Specified by:
keyin interfaceCryptoContext- Returns:
- the secret key
-
setContext
Sets the Conflux session context used to exchange IV/AAD/tagBits and to enable header I/O.- Specified by:
setContextin interfaceContextAware- Parameters:
context- the context; may benullto disable context features
-
context
Returns the currently set Conflux context (possiblynull).- Specified by:
contextin interfaceContextAware- Returns:
- the context or
null
-
attach
Attaches this context to an upstream stream and returns a transforming stream.- Decrypt + header → reads header first, hydrates context, then transforms
- Transform → initializes JCA cipher with IV/AAD (GCM), staging final output if necessary
- Encrypt + header → prepends header after IV is determined
- Specified by:
attachin interfaceEncryptionContext- Parameters:
upstream- the source stream; not null- Returns:
- a stream that yields ciphertext (encrypt) or plaintext (decrypt)
- Throws:
IOException- on I/O or provider errors; includes IV length mismatches and missing IV for decrypt
-
close
public void close()Description copied from interface:CryptoContextCompletes the context's implementation-specific cleanup.Implementations release resources they explicitly own; cleanup can be a no-op for contexts holding only borrowed or garbage-collected state. The bound key remains caller-owned: closing a context never destroys the key. Callers that own a destroyable key must destroy it explicitly after all contexts and other consumers have released it. Streams returned by the context have independent lifecycles: callers must complete and close those streams before closing the context. This method does not promise to finalize stream output or verify authentication tags.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCryptoContext
-