java.lang.Object
net.i2p.crypto.elgamal.impl.ElGamalPrivateKeyImpl
- All Implemented Interfaces:
Serializable, AsymmetricKey, BinaryEncodablePREVIEW, Key, PrivateKey, DHKey, DHPrivateKey, Destroyable, ElGamalKey, ElGamalPrivateKey
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:
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ElGamalParameterSpecEl spec.private static final longPinned for serialized-form compatibility.private BigIntegerThe private exponent x.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a key with no parameters, set later by decoding.ElGamalPrivateKeyImpl(BigInteger x, ElGamalParameterSpec elSpec) Create from the private exponent and parameters.Constructor from PKCS8 key spec.Create from a DH private key.Create from a DH private key spec.Create a copy of the given ElGamal private key.Create from an ElGamal private key spec.Method Summary
Modifier and TypeMethodDescriptionThe algorithm name, "ElGamal".byte[]Return a PKCS8 representation of the key.The encoding format produced bygetEncoded().The ElGamal parameters for this key.The parameters for this key.getX()The private exponent.private voidRead object.private voidWrite object.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Destroyable
destroy, isDestroyed
Field Details
serialVersionUID
private static final long serialVersionUIDPinned for serialized-form compatibility.- See Also:
x
The private exponent x.elSpec
El spec.
Constructor Details
ElGamalPrivateKeyImpl
protected ElGamalPrivateKeyImpl()Creates a key with no parameters, set later by decoding.ElGamalPrivateKeyImpl
Create a copy of the given ElGamal private key.- Parameters:
key- the ElGamal private key, read for both its exponent and its parameters
ElGamalPrivateKeyImpl
Create from a DH private key.- Parameters:
key- the DH private key
ElGamalPrivateKeyImpl
Create from an ElGamal private key spec.- Parameters:
spec- the ElGamal private key spec
ElGamalPrivateKeyImpl
Create from a DH private key spec.- Parameters:
spec- the DH private key spec
ElGamalPrivateKeyImpl
Create from the private exponent and parameters.- Parameters:
x- The private exponent.elSpec- The ElGamal parameters.
ElGamalPrivateKeyImpl
Constructor from PKCS8 key spec.- Parameters:
spec- the PKCS8 key spec- Throws:
InvalidKeySpecException- always, not yet implemented
Method Details
getAlgorithm
The algorithm name, "ElGamal".- Specified by:
getAlgorithmin interfaceKey- Returns:
- the algorithm name, always "ElGamal"
getFormat
The encoding format produced bygetEncoded().getEncoded
public byte[] getEncoded()Return a PKCS8 representation of the key. The sequence returned represents a full PrivateKeyInfo object.- Specified by:
getEncodedin interfaceKey- Returns:
- a PKCS8 representation of the key.
getParameters
The ElGamal parameters for this key.- Specified by:
getParametersin interfaceElGamalKey- Returns:
- the ElGamal group this key belongs to
getParams
The parameters for this key.- Specified by:
getParamsin interfaceAsymmetricKey- Specified by:
getParamsin interfaceDHKey- Specified by:
getParamsin interfaceDHPrivateKey- Returns:
- the ElGamal group as a DH parameter spec, discarding the ElGamal extras
getX
The private exponent.- Specified by:
getXin interfaceDHPrivateKey- Specified by:
getXin interfaceElGamalPrivateKey- Returns:
- the private exponent x
readObject
Read object.- Parameters:
in- the stream positioned at the serialized exponent and group parameters- Throws:
IOException- if the stream cannot be read or ends before the group parametersClassNotFoundException- if a class named in the stream cannot be resolved
writeObject
Write object.- Parameters:
out- the stream that receives the exponent and both group parameters- Throws:
IOException- if the underlying stream rejects or fails the write