Class ElgamalPrivateKeySpec

java.lang.Object
zeroecho.core.alg.elgamal.ElgamalPrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class ElgamalPrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable

ElGamal Private Key Specification

Wrapper for a PKCS#8-encoded ElGamal private key.

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

Contents

Usage

// Import from PKCS#8 DER
byte[] der = Files.readAllBytes(Path.of("elgamal-priv.der"));
ElgamalPrivateKeySpec spec = new ElgamalPrivateKeySpec(der);
PrivateKey priv = algo.privateKeyImporter(ElgamalPrivateKeySpec.class).importPrivate(spec);

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

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

Security considerations

  • Private key material must be protected in memory and at rest. The spec itself does not attempt to zeroize its contents.
  • Always prefer secure storage (e.g., a hardware module) over raw byte handling when possible.

Thread-safety

Access and destruction are synchronized.
Since:
1.0
  • Constructor Details

    • ElgamalPrivateKeySpec

      public ElgamalPrivateKeySpec(byte[] pkcs8)
      Constructs a new private key spec from PKCS#8-encoded bytes.
      Parameters:
      pkcs8 - PKCS#8 DER encoding of the private key; must not be null
  • Method Details

    • encoded

      public byte[] encoded()
      Returns a defensive copy of the PKCS#8-encoded private key.
      Returns:
      PKCS#8 DER encoding
    • marshal

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

      The output includes:

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

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

      public void destroy()
      Specified by:
      destroy in interface Destroyable
    • isDestroyed

      public boolean isDestroyed()
      Specified by:
      isDestroyed in interface Destroyable