Class ElgamalAlgorithm


public final class ElgamalAlgorithm extends AbstractCryptoAlgorithm

ElGamal Asymmetric Encryption Algorithm

Concrete CryptoAlgorithm for the ElGamal public-key encryption scheme.

ElGamal is an asymmetric cryptosystem based on the hardness of the discrete logarithm problem in a finite cyclic group. It provides semantic security under chosen-plaintext attacks when combined with proper padding (e.g., PKCS#1 style). This implementation delegates to the Bouncy Castle provider ("BC") for underlying primitives and parameter generation.

Note: OAEP is not offered for ElGamal; for modern IND-CCA security prefer KEM or KEM-DEM constructions such as DHIES, ECIES, or Cramer-Shoup, or use a KEM provided elsewhere in the catalog.

Declared capabilities

Key material

Provider requirements

This implementation requires the Bouncy Castle JCE provider to be registered under the name "BC". If unavailable, ensureBC() will throw a NoSuchProviderException.

Thread-safety

Instances of ElgamalAlgorithm are immutable and may be safely shared across threads. Generated CryptoContext instances are not necessarily thread-safe.

Example

CryptoAlgorithm algo = new ElgamalAlgorithm();
KeyPair kp = algo.asymmetricKeyPairGenerator(ElgamalParamSpec.class)
                 .generateKeyPair(ElgamalParamSpec.ffdhe2048());

EncryptionContext enc = algo.createContext(KeyUsage.ENCRYPT, kp.getPublic(),
                                    ElgamalEncSpec.pkcs1());
EncryptionContext dec = algo.createContext(KeyUsage.DECRYPT, kp.getPrivate(),
                                    ElgamalEncSpec.pkcs1());
Since:
1.0
  • Constructor Details

    • ElgamalAlgorithm

      public ElgamalAlgorithm()
      Constructs a new ElGamal algorithm instance bound to the "ElGamal" identifier and backed by the Bouncy Castle provider.

      During construction, the algorithm registers:

      • Encryption and decryption capabilities,
      • Key builders for parameter-based, public, and private key specs,
      • Default parameter spec suppliers (e.g., ffdhe2048).
  • 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