Class ElgamalPublicKeySpec
java.lang.Object
zeroecho.core.alg.elgamal.ElgamalPublicKeySpec
- All Implemented Interfaces:
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
encoded()returns a defensive copy of the raw X.509 bytes.marshal(ElgamalPublicKeySpec)encodes the key into aPairSeqstructure for transport or logging.unmarshal(PairSeq)reconstructs the spec from a marshalled representation.
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 Summary
ConstructorsConstructorDescriptionElgamalPublicKeySpec(byte[] x509) Constructs a new public key spec from X.509-encoded bytes. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]encoded()Returns a defensive copy of the X.509-encoded public key.static PairSeqmarshal(ElgamalPublicKeySpec spec) Serializes this spec into aPairSeq.static ElgamalPublicKeySpecParses aPairSeqand reconstructs anElgamalPublicKeySpec.
-
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 benull
-
-
Method Details
-
encoded
public byte[] encoded()Returns a defensive copy of the X.509-encoded public key.- Returns:
- X.509 DER encoding
-
marshal
-
unmarshal
Parses aPairSeqand reconstructs anElgamalPublicKeySpec.- Parameters:
p- encoded pair sequence- Returns:
- new public key spec
- Throws:
IllegalArgumentException- if required fieldx509.b64is missing
-