java.lang.Object
net.i2p.crypto.elgamal.impl.ElGamalPublicKeyImpl
- All Implemented Interfaces:
Serializable, AsymmetricKey, BinaryEncodablePREVIEW, Key, PublicKey, DHKey, DHPublicKey, ElGamalKey, ElGamalPublicKey
Implementation of ElGamal public keys.
This class provides a concrete implementation of the ElGamalPublicKey interface, representing the public component of an ElGamal key pair. It stores the public value y = g^x mod p and the ElGamal parameters (prime p and generator g), and supports X.509 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 public value y = g^x mod p.Constructor Summary
ConstructorsConstructorDescriptionElGamalPublicKeyImpl(BigInteger y, ElGamalParameterSpec elSpec) Builds a key from a bare public value and its parameters.Rejects X.509 encoding, which is not implemented here.Copies an existing DH public key into ElGamal form.Adopts the y value and parameters of a DH key spec.Copies an existing ElGamal public key.Adopts the y value and parameters of an ElGamal key spec.Method Summary
Modifier and TypeMethodDescriptionbooleanCompare this key with another object.Names the ElGamal algorithm this key belongs to.byte[]Serialises p, g and y into the X.509 SubjectPublicKeyInfo form.Names the X.509 encoding this key serialises to.Fetches the ElGamal group parameters.Wraps the same group parameters in a fresh DH spec.getY()The public value y = g^x mod p.inthashCode()Hash code of this key.private voidRead object.(package private) static intspaceFor(int val) Calculate the TLV space for a value of the given length.private voidWrite object.
Field Details
serialVersionUID
private static final long serialVersionUIDPinned for serialized-form compatibility.- See Also:
y
The public value y = g^x mod p.elSpec
El spec.
Constructor Details
ElGamalPublicKeyImpl
Adopts the y value and parameters of an ElGamal key spec.- Parameters:
spec- the ElGamal public key spec
ElGamalPublicKeyImpl
Adopts the y value and parameters of a DH key spec.- Parameters:
spec- the DH public key spec
ElGamalPublicKeyImpl
Copies an existing ElGamal public key.- Parameters:
key- the ElGamal public key to copy
ElGamalPublicKeyImpl
Copies an existing DH public key into ElGamal form.- Parameters:
key- the DH public key to copy
ElGamalPublicKeyImpl
Builds a key from a bare public value and its parameters.- Parameters:
y- the public value y = g^x mod pelSpec- the ElGamal parameters
ElGamalPublicKeyImpl
Rejects X.509 encoding, which is not implemented here.- Parameters:
spec- the X.509 key spec- Throws:
InvalidKeySpecException- always, not yet implemented
Method Details
getAlgorithm
Names the ElGamal algorithm this key belongs to.- Specified by:
getAlgorithmin interfaceKey- Returns:
- the JCA algorithm name for this key, always "ElGamal"
getFormat
getEncoded
public byte[] getEncoded()Serialises p, g and y into the X.509 SubjectPublicKeyInfo form.- Specified by:
getEncodedin interfaceKey- Returns:
- the X.509 SubjectPublicKeyInfo encoding, a DER sequence holding p, g and y
spaceFor
static int spaceFor(int val) Calculate the TLV space for a value of the given length.- Parameters:
val- the length of the value, 65535 max- Returns:
- the length of the TLV
getParameters
Fetches the ElGamal group parameters.- Specified by:
getParametersin interfaceElGamalKey- Returns:
- the ElGamal group parameters this key was built with, never null
getParams
Wraps the same group parameters in a fresh DH spec.- Specified by:
getParamsin interfaceAsymmetricKey- Specified by:
getParamsin interfaceDHKey- Specified by:
getParamsin interfaceDHPublicKey- Returns:
- a newly built DH spec carrying the same prime p and generator g
getY
The public value y = g^x mod p.- Specified by:
getYin interfaceDHPublicKey- Specified by:
getYin interfaceElGamalPublicKey- Returns:
- the public value y = g^x mod p, never null
equals
hashCode
readObject
Read object.- Parameters:
in- the stream to deserialize the y value and the ElGamal parameters from- Throws:
IOException- if the stream cannot be readClassNotFoundException- if the serialized class is not available to this router
writeObject
Write object.- Parameters:
out- the stream to serialize the y value and the ElGamal parameters to- Throws:
IOException- if the stream cannot be written