Class DhAlgorithm
This class registers a Diffie-Hellman (DH) algorithm under the identifier
"DH" with sane defaults and JCA compatibility. It declares the
algorithm’s capabilities, default parameters, and key builders so that higher
layers can use DH for key agreement in a consistent and type-safe way.
Features
- Algorithm identifier and display name:
"DH". - Agreement capability producing
AgreementContextinstances backed by the JCA algorithm name"DiffieHellman". - Default parameter specification:
DhSpec.ffdhe2048(). - Asymmetric key builder for
DhSpec-based key pair generation viaDhKeyGenBuilder. - Support for importing keys from
DhPublicKeySpecandDhPrivateKeySpecusing standard JCA key factories.
Thread-safety
Instances ofDhAlgorithm are immutable after
construction. They are typically created once at application startup and
safely reused across threads as shared registrations in a
CryptoCatalog.
Usage example
// Create and register the algorithm
DhAlgorithm dh = new DhAlgorithm();
CryptoCatalog catalog = CryptoCatalog.load();
// Create a DH spec (or rely on the default ffdhe2048)
DhSpec spec = DhSpec.ffdhe3072();
// Generate a key pair using the registered builder
KeyPair kp = session.keyBuilders().asymmetric().generateKeyPair("DH", spec);
// Obtain an agreement context for DH key agreement
AgreementContext ctx = session.createContext("DH", KeyUsage.AGREEMENT, kp.getPrivate(), spec);
// Use the context with a peer public key to derive a shared secret
ctx.setPeerPublic(peerPublicKey);
byte[] secret = ctx.deriveSecret();
- Since:
- 1.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a Diffie-Hellman algorithm registration with standard defaults. -
Method Summary
Modifier and TypeMethodDescriptionList<ParameterSetDescriptor<? extends AlgorithmKeySpec>> Returns the discoverable parameter sets (or parameterized templates) supported by this algorithm.Methods inherited from class AbstractCryptoAlgorithm
capabilityMethods inherited from class CryptoAlgorithm
addCapability, asymmetricKeyPairGenerator, bindContext, createContext, displayName, id, keyOperations, listCapabilities, priority, privateKeyImporter, providerName, publicKeyImporter, registerAsymmetricKeyPairGenerator, registerPrivateKeyImporter, registerPublicKeyImporter, registerSymmetricKeyGenerator, registerSymmetricKeyImporter, requiresStatefulSigning, roles, supports, symmetricKeyGenerator, symmetricKeyImporter
-
Constructor Details
-
DhAlgorithm
public DhAlgorithm()Creates a Diffie-Hellman algorithm registration with standard defaults.This constructor:
- Registers the algorithm under the identifier
"DH"and display name"DH". - Declares an
AlgorithmFamily.AGREEMENTcapability forKeyUsage.AGREEMENT, producingGenericJcaAgreementContextinstances bound to the JCA name"DiffieHellman". - Sets
DhSpec.ffdhe2048()as the default parameter specification. - Registers
DhKeyGenBuilderas the asymmetric key builder forDhSpec. - Registers asymmetric key builders for importing keys via
DhPublicKeySpecandDhPrivateKeySpecusing JCAKeyFactory.
- Registers the algorithm under the identifier
-
-
Method Details
-
parameterSets
Description copied from class:CryptoAlgorithmReturns the discoverable parameter sets (or parameterized templates) supported by this algorithm.Callers (UIs, provisioning tools, policy engines) use this list to present users with valid, named key-generation options without prior knowledge of the concrete algorithm. Each entry is either a pre-built
ParameterSetDescriptor.Concrete(ready spec) or aParameterSetDescriptor.Template(user-supplied arguments produce the spec).The default implementation returns an empty list. Algorithms with finite, enumerable parameter sets should override this method. Overrides must return immutable lists in stable order, with unique nonblank descriptor identifiers. Registry loading validates a snapshot; external providers remain responsible for maintaining the contract on subsequent calls. Implementations may use
ParameterSetDescriptor.snapshot(List)to validate and copy their list.- Overrides:
parameterSetsin classCryptoAlgorithm- Returns:
- immutable list of parameter set descriptors; never
null
-