Class DhPublicKeySpec
java.lang.Object
zeroecho.core.alg.dh.DhPublicKeySpec
- All Implemented Interfaces:
AlgorithmKeySpec
Key specification for a Diffie-Hellman public key encoded in X.509 format.
This spec carries the raw encoded public key bytes in the standard X.509
SubjectPublicKeyInfo form. It is intended for use with algorithms in the
AlgorithmFamily.AGREEMENT family, allowing safe
import/export of DH public keys across contexts.
Design
- Immutable: the internal byte array is defensively copied at construction
and when returned by
encoded(). - 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 public key from encoded bytes
DhPublicKeySpec spec = new DhPublicKeySpec(x509Bytes);
PublicKey pub = session.keyBuilders().asymmetric().importPublic("DH", spec);
// Marshal to a text-friendly representation
PairSeq ps = DhPublicKeySpec.marshal(spec);
// Unmarshal back to spec
DhPublicKeySpec parsed = DhPublicKeySpec.unmarshal(ps);
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionDhPublicKeySpec(byte[] key) Creates a new specification from an X.509 encoded DH public key. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]encoded()Returns a clone of the encoded X.509 bytes.static PairSeqmarshal(DhPublicKeySpec spec) Marshals the given DH public key spec into aPairSeq.static DhPublicKeySpecReconstructs aDhPublicKeySpecfrom aPairSeq.
-
Constructor Details
-
DhPublicKeySpec
public DhPublicKeySpec(byte[] key) Creates a new specification from an X.509 encoded DH public key.- Parameters:
key- the encoded public key bytes; must not benull- Throws:
NullPointerException- ifkeyisnull
-
-
Method Details
-
encoded
public byte[] encoded()Returns a clone of the encoded X.509 bytes.- Returns:
- a defensive copy of the X.509 encoded DH public key
-
marshal
Marshals the given DH public key spec into aPairSeq.The sequence contains a
typefield with value"DH-PUB"and anx509.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 aDhPublicKeySpecfrom aPairSeq.The sequence must contain an
x509.b64field with the Base64-encoded public key. If this field is missing, anIllegalArgumentExceptionis thrown.- Parameters:
p- the sequence to decode- Returns:
- a new spec containing the decoded X.509 bytes
- Throws:
IllegalArgumentException- if required fields are missing or malformed
-