Class ElgamalPrivateKeySpec
java.lang.Object
zeroecho.core.alg.elgamal.ElgamalPrivateKeySpec
- All Implemented Interfaces:
Destroyable, AlgorithmKeySpec
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
encoded()returns a defensive copy of the raw PKCS#8 bytes.marshal(ElgamalPrivateKeySpec)encodes the key into aPairSeqstructure for transport or logging.unmarshal(PairSeq)reconstructs the spec from a marshalled representation.
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 Summary
ConstructorsConstructorDescriptionElgamalPrivateKeySpec(byte[] pkcs8) Constructs a new private key spec from PKCS#8-encoded bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()byte[]encoded()Returns a defensive copy of the PKCS#8-encoded private key.booleanstatic PairSeqmarshal(ElgamalPrivateKeySpec spec) Serializes this spec into aPairSeq.static ElgamalPrivateKeySpecParses aPairSeqand reconstructs anElgamalPrivateKeySpec.
-
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 benull
-
-
Method Details
-
encoded
public byte[] encoded()Returns a defensive copy of the PKCS#8-encoded private key.- Returns:
- PKCS#8 DER encoding
-
marshal
-
unmarshal
Parses aPairSeqand reconstructs anElgamalPrivateKeySpec.- Parameters:
p- encoded pair sequence- Returns:
- new private key spec
- Throws:
IllegalArgumentException- if required fieldpkcs8.b64is missing
-
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-