Class DhAlgorithm


public final class DhAlgorithm extends AbstractCryptoAlgorithm
Diffie-Hellman algorithm registration for use in the pluggable cryptography catalog.

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

Thread-safety

Instances of DhAlgorithm 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 Details

  • Method Details

    • parameterSets

      public List<ParameterSetDescriptor<? extends AlgorithmKeySpec>> parameterSets()
      Description copied from class: CryptoAlgorithm
      Returns 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 a ParameterSetDescriptor.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:
      parameterSets in class CryptoAlgorithm
      Returns:
      immutable list of parameter set descriptors; never null