Interface DigestContext
- All Superinterfaces:
AutoCloseable, Closeable, CryptoContext, TagEngine<byte[]>
- All Known Implementing Classes:
JcaDigestContext
Context for computing unkeyed message digests and extendable-output functions
(XOFs) in streaming pipelines.
A DigestContext combines digest/XOF state with the TagEngine
contract: the wrapped input stream passes bytes through while updating the
computation; at end-of-file, a fixed-length tag is appended (produce mode) or
compared with an expected tag (verify mode).
Operation
- Produce mode:
TagEngine.wrap(java.io.InputStream)emits the original data, then appends the digest (or configured-length XOF output) as a trailer. - Verify mode: Provide the expected tag via
TagEngine.setExpectedTag(byte[]); the engine compares the computed tag at EOF using the configured verification approach.
Usage
Digest trailer
TagEngine<byte[]> eng = TagEngineBuilder.digest(DigestSpec.sha256()).get();
try (java.io.InputStream in = eng.wrap(upstream)) {
in.transferTo(out);
}
Detached verification
TagEngine<byte[]> eng = TagEngineBuilder.digest(DigestSpec.sha256()).get();
eng.setExpectedTag(expectedDigest);
try (java.io.InputStream in = eng.wrap(bodyWithoutTrailer)) {
in.transferTo(java.io.OutputStream.nullOutputStream());
}
Security considerations
- Unkeyed digests do not provide authenticity; use
MacContextorSignatureContextfor that. - For XOFs, choose an output length appropriate for your security level.
- Implementations are stateful and not guaranteed to be thread-safe.
- Since:
- 1.0
-
Field Summary
-
Method Summary
Methods inherited from interface CryptoContext
algorithm, close, keyMethods inherited from interface TagEngine
getVerificationCore, setExpectedTag, setVerificationApproach, tagLength, wrap