java.lang.Object
net.i2p.crypto.elgamal.impl.ElGamalPrivateKeyImpl
All Implemented Interfaces:
Serializable, AsymmetricKey, BinaryEncodablePREVIEW, Key, PrivateKey, DHKey, DHPrivateKey, Destroyable, ElGamalKey, ElGamalPrivateKey

public class ElGamalPrivateKeyImplextends Object implements ElGamalPrivateKey, DHPrivateKey
Implementation of ElGamal private keys.

This class provides a concrete implementation of the ElGamalPrivateKey interface, representing the private component of an ElGamal key pair. It stores the secret exponent x and the ElGamal parameters (prime p and generator g), and supports PKCS#8 encoding for standardized key storage and transmission.

See Also:
  • Constructor Details

    • ElGamalPrivateKeyImpl

      protected ElGamalPrivateKeyImpl()
      No-arg constructor.
    • ElGamalPrivateKeyImpl

      public ElGamalPrivateKeyImpl(ElGamalPrivateKey key)
      Create a copy of the given ElGamal private key.
      Parameters:
      key - the ElGamal private key, read for both its exponent and its parameters
    • ElGamalPrivateKeyImpl

      public ElGamalPrivateKeyImpl(DHPrivateKey key)
      Create from a DH private key.
      Parameters:
      key - the DH private key
    • ElGamalPrivateKeyImpl

      public ElGamalPrivateKeyImpl(ElGamalPrivateKeySpec spec)
      Create from an ElGamal private key spec.
      Parameters:
      spec - the ElGamal private key spec
    • ElGamalPrivateKeyImpl

      public ElGamalPrivateKeyImpl(DHPrivateKeySpec spec)
      Create from a DH private key spec.
      Parameters:
      spec - the DH private key spec
    • ElGamalPrivateKeyImpl

      public ElGamalPrivateKeyImpl(BigInteger x, ElGamalParameterSpec elSpec)
      Create from the private exponent and parameters.
      Parameters:
      x - The private exponent.
      elSpec - The ElGamal parameters.
    • ElGamalPrivateKeyImpl

      public ElGamalPrivateKeyImpl(PKCS8EncodedKeySpec spec) throws InvalidKeySpecException
      Constructor from PKCS8 key spec.
      Parameters:
      spec - the PKCS8 key spec
      Throws:
      InvalidKeySpecException - always, not yet implemented
  • Method Details

    • getAlgorithm

      public String getAlgorithm()
      The algorithm name, "ElGamal".
      Specified by:
      getAlgorithm in interface Key
      Returns:
      the algorithm name, always "ElGamal"
    • getFormat

      public String getFormat()
      The encoding format produced by getEncoded().
      Specified by:
      getFormat in interface Key
      Returns:
      the encoding format name, always "PKCS#8"
    • getEncoded

      public byte[] getEncoded()
      Return a PKCS8 representation of the key. The sequence returned represents a full PrivateKeyInfo object.
      Specified by:
      getEncoded in interface Key
      Returns:
      a PKCS8 representation of the key.
    • getParameters

      public ElGamalParameterSpec getParameters()
      The ElGamal parameters for this key.
      Specified by:
      getParameters in interface ElGamalKey
      Returns:
      the ElGamal group this key belongs to
    • getParams

      public DHParameterSpec getParams()
      The parameters for this key.
      Specified by:
      getParams in interface AsymmetricKey
      Specified by:
      getParams in interface DHKey
      Specified by:
      getParams in interface DHPrivateKey
      Returns:
      the ElGamal group as a DH parameter spec, discarding the ElGamal extras
    • getX

      public BigInteger getX()
      The private exponent.
      Specified by:
      getX in interface DHPrivateKey
      Specified by:
      getX in interface ElGamalPrivateKey
      Returns:
      the private exponent x