Class DhPrivateKeySpec
java.lang.Object
zeroecho.core.alg.dh.DhPrivateKeySpec
- All Implemented Interfaces:
Destroyable, AlgorithmKeySpec
Key specification for a Diffie-Hellman private key encoded in PKCS#8 format.
This spec encapsulates the raw encoded private key bytes following the
standard PKCS#8 structure. It is used with algorithms in the
AlgorithmFamily.AGREEMENT family, allowing safe
import/export of DH private keys across contexts.
Design
- Destroyable: the internal byte array is defensively copied at
construction and when returned by
encoded(), and is cleared bydestroy(). - Encodable: supports marshaling to/from a
PairSeqso keys can be serialized in human-readable or protocol-friendly formats. - Type-safe: used as a binding for asymmetric key builders within
CryptoAlgorithmdefinitions.
Example
// Import a DH private key from encoded bytes
DhPrivateKeySpec spec = new DhPrivateKeySpec(pkcs8Bytes);
PrivateKey priv = session.keyBuilders().asymmetric().importPrivate("DH", spec);
// Marshal to a text-friendly representation
PairSeq ps = DhPrivateKeySpec.marshal(spec);
// Unmarshal back to spec
DhPrivateKeySpec parsed = DhPrivateKeySpec.unmarshal(ps);
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionDhPrivateKeySpec(byte[] pkcs8) Creates a new specification from a PKCS#8 encoded DH private key. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()byte[]encoded()Returns a clone of the encoded PKCS#8 bytes.booleanstatic PairSeqmarshal(DhPrivateKeySpec spec) Marshals the given DH private key spec into aPairSeq.static DhPrivateKeySpecReconstructs aDhPrivateKeySpecfrom aPairSeq.
-
Constructor Details
-
DhPrivateKeySpec
public DhPrivateKeySpec(byte[] pkcs8) Creates a new specification from a PKCS#8 encoded DH private key.- Parameters:
pkcs8- the encoded private key bytes; must not benull- Throws:
IllegalArgumentException- ifpkcs8isnull
-
-
Method Details
-
encoded
public byte[] encoded()Returns a clone of the encoded PKCS#8 bytes.- Returns:
- a defensive copy of the PKCS#8 encoded DH private key
-
marshal
Marshals the given DH private key spec into aPairSeq.The sequence contains a
typefield with value"DH-PRIV"and apkcs8.b64field with the Base64 encoding of the key.- Parameters:
spec- the spec to encode- Returns:
- a
PairSeqrepresentation of the spec - Throws:
NullPointerException- ifspecisnull
-
unmarshal
Reconstructs aDhPrivateKeySpecfrom aPairSeq.The sequence must contain a
pkcs8.b64field with the Base64-encoded private key. If this field is missing, anIllegalArgumentExceptionis thrown.- Parameters:
p- the sequence to decode- Returns:
- a new spec containing the decoded PKCS#8 bytes
- Throws:
IllegalArgumentException- if required fields are missing or malformed
-
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-