Class ElgamalPublicKeySpec

java.lang.Object
zeroecho.core.alg.elgamal.ElgamalPublicKeySpec
All Implemented Interfaces:
AlgorithmKeySpec

public final class ElgamalPublicKeySpec extends Object implements AlgorithmKeySpec

ElGamal Public Key Specification

Wrapper for an X.509-encoded ElGamal public key.

This specification serves as the input to key-import routines, providing a portable representation of public key material. The encoding format is assumed to be X.509 DER, as produced by standard JCA/JCE providers.

Contents

Usage

// Import from X.509 DER
byte[] der = Files.readAllBytes(Path.of("elgamal-pub.der"));
ElgamalPublicKeySpec spec = new ElgamalPublicKeySpec(der);
PublicKey pub = algo.publicKeyImporter(ElgamalPublicKeySpec.class).importPublic(spec);

// Marshal for serialization
PairSeq ps = ElgamalPublicKeySpec.marshal(spec);

// Unmarshal back
ElgamalPublicKeySpec restored = ElgamalPublicKeySpec.unmarshal(ps);

Security considerations

  • Public keys are not secret, but they must be bound to the correct parameters (modulus and generator) to avoid substitution attacks.
  • Always validate public key encoding against trusted parameter sets before using in protocols.

Thread-safety

Instances are immutable and safe to share between threads.
Since:
1.0
  • Constructor Details

    • ElgamalPublicKeySpec

      public ElgamalPublicKeySpec(byte[] x509)
      Constructs a new public key spec from X.509-encoded bytes.
      Parameters:
      x509 - X.509 DER encoding of the public key; must not be null
  • Method Details

    • encoded

      public byte[] encoded()
      Returns a defensive copy of the X.509-encoded public key.
      Returns:
      X.509 DER encoding
    • marshal

      public static PairSeq marshal(ElgamalPublicKeySpec spec)
      Serializes this spec into a PairSeq.

      The output includes:

      • type = "ELGAMAL-PUB"
      • x509.b64 = Base64 encoding of the DER bytes (without padding)
      Parameters:
      spec - ElGamal public key spec
      Returns:
      marshalled key as PairSeq
    • unmarshal

      public static ElgamalPublicKeySpec unmarshal(PairSeq p)
      Parses a PairSeq and reconstructs an ElgamalPublicKeySpec.
      Parameters:
      p - encoded pair sequence
      Returns:
      new public key spec
      Throws:
      IllegalArgumentException - if required field x509.b64 is missing