Class XdhPublicKeySpec
java.lang.Object
zeroecho.core.alg.xdh.XdhPublicKeySpec
- All Implemented Interfaces:
AlgorithmKeySpec
Key specification for an XDH (elliptic curve Diffie-Hellman) public key.
This class encapsulates the X.509-encoded representation of a public key used
in modern Diffie-Hellman style agreements such as X25519 or X448. It provides
safe construction, serialization, and deserialization utilities suitable for
persistence, transmission, or integration with
CryptoAlgorithm key builders.
Design goals
- Encapsulation: the encoded key bytes are cloned defensively on input and output to prevent accidental modification.
- Interoperability: supports round-trip conversion to/from
PairSeqwith base64 encoding. - Validation: throws explicit exceptions when mandatory fields are missing.
Usage
// Construct from an X.509-encoded public key
byte[] encoded = ...; // obtained from a certificate or peer
XdhPublicKeySpec spec = new XdhPublicKeySpec(encoded);
// Marshal to a serializable structure
PairSeq p = XdhPublicKeySpec.marshal(spec);
// Unmarshal back from serialized form
XdhPublicKeySpec spec2 = XdhPublicKeySpec.unmarshal(p);
assert Arrays.equals(spec.encoded(), spec2.encoded());
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionXdhPublicKeySpec(byte[] key) Constructs a new specification from the given X.509-encoded public key. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]encoded()Returns a defensive copy of the X.509-encoded public key bytes.static PairSeqmarshal(XdhPublicKeySpec spec) Serializes the given key specification into aPairSeqwith base64 encoding.static XdhPublicKeySpecDeserializes a specification from the givenPairSeq.
-
Constructor Details
-
XdhPublicKeySpec
public XdhPublicKeySpec(byte[] key) Constructs a new specification from the given X.509-encoded public key.- Parameters:
key- the raw encoded key bytes, must not benull- Throws:
NullPointerException- ifkeyisnull
-
-
Method Details
-
encoded
public byte[] encoded()Returns a defensive copy of the X.509-encoded public key bytes.- Returns:
- a clone of the internal key encoding
-
marshal
Serializes the given key specification into aPairSeqwith base64 encoding.The output contains two entries:
type = "XDH-PUB"x509.b64 = <base64-encoded key>
- Parameters:
spec- the specification to marshal- Returns:
- a pair sequence containing the encoded key
- Throws:
NullPointerException- ifspecisnull
-
unmarshal
Deserializes a specification from the givenPairSeq.The sequence must contain an entry
x509.b64with a base64-encoded key. Additional entries are ignored.- Parameters:
p- the pair sequence containing serialized fields- Returns:
- a reconstructed
XdhPublicKeySpec - Throws:
IllegalArgumentException- ifx509.b64is missing or cannot be decoded
-