Interface CryptoContext
- All Superinterfaces:
AutoCloseable, Closeable
- All Known Subinterfaces:
AgreementContext, DigestContext, EncryptionContext, KemContext, MacContext, MessageAgreementContext, SignatureContext
- All Known Implementing Classes:
AesCipherContext, BikeKemContext, ChaChaCipherContext, CmceKemContext, CommonEdDSASignatureContext, Ed25519SignatureContext, Ed448SignatureContext, ElgamalCipherContext, FrodoKemContext, GenericJcaAgreementContext, GenericJcaMessageAgreementContext, GenericJcaSignatureContext, HmacMacContext, HqcKemContext, HybridKexContext, JcaDigestContext, KemMessageAgreementAdapter, KyberKemContext, LmsSignatureContext, MldsaSignatureContext, NtruKemContext, NtrulPrimeKemContext, RsaCipherContext, RsaSignatureContext, SaberKemContext, SlhDsaSignatureContext, SntruPrimeKemContext, SphincsPlusSignatureContext, XmssSignatureContext, XWingKemContext
A CryptoContext represents the active state of an algorithm bound to
a specific key and optional parameters. Contexts encapsulate resources such
as cipher instances, digest engines, or signature state machines. They are
created by a CryptoAlgorithm for a particular
KeyUsage role and remain valid until close()
is called.
Lifecycle
- Contexts are created via
ZeroEchoSession#createContext(...). - They may wrap native or provider-managed resources that must be released.
- Callers must stop using a context after closing it. This is a caller lifecycle obligation, not a guarantee that subsequent calls are rejected; some implementations have no context-owned resources and close is a no-op.
Security considerations
- Bound keys are borrowed from the caller and are never destroyed by context closure.
- Applications should call
close()promptly. Closing is not a guarantee of erasing provider-managed key material or Java heap copies. - Contexts are not guaranteed to be thread-safe; concurrent use should be avoided unless explicitly documented by the implementation.
Subtypes
Concrete context kinds are represented by specialized subinterfaces:DigestContext- unkeyed hash and XOF pipelinesEncryptionContext- symmetric/asymmetric encryption and decryption streamsMacContext- message authentication codesSignatureContext- digital signatures (sign/verify)AgreementContext- key agreement protocolsKemContext- key encapsulation mechanisms (KEM)
- Since:
- 1.0
-
Method Details
-
algorithm
CryptoAlgorithm algorithm()Returns the algorithm that created this context.- Returns:
- the algorithm definition that owns this context
-
key
Key key()Returns the key bound to this context.For unkeyed contexts such as digests, this may be
NullKey.INSTANCE.- Returns:
- the cryptographic key or sentinel bound to this context
-
close
Completes 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- Throws:
IOException- if the underlying provider encounters an I/O error during cleanup
-