Class XdhPrivateKeySpec
java.lang.Object
zeroecho.core.alg.xdh.XdhPrivateKeySpec
- All Implemented Interfaces:
Destroyable, AlgorithmKeySpec
Key specification for an XDH (elliptic curve Diffie-Hellman) private key.
This class encapsulates the PKCS#8-encoded representation of a private 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 a PKCS#8-encoded private key
byte[] encoded = ...; // obtained from key generation or storage
XdhPrivateKeySpec spec = new XdhPrivateKeySpec(encoded);
// Marshal to a serializable structure
PairSeq p = XdhPrivateKeySpec.marshal(spec);
// Unmarshal back from serialized form
XdhPrivateKeySpec spec2 = XdhPrivateKeySpec.unmarshal(p);
assert Arrays.equals(spec.encoded(), spec2.encoded());
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionXdhPrivateKeySpec(byte[] pkcs8) Constructs a new specification from the given PKCS#8-encoded private key. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()byte[]encoded()Returns a defensive copy of the PKCS#8-encoded private key bytes.booleanstatic PairSeqmarshal(XdhPrivateKeySpec spec) Serializes the given key specification into aPairSeqwith base64 encoding.static XdhPrivateKeySpecDeserializes a specification from the givenPairSeq.
-
Constructor Details
-
XdhPrivateKeySpec
public XdhPrivateKeySpec(byte[] pkcs8) Constructs a new specification from the given PKCS#8-encoded private key.- Parameters:
pkcs8- the raw encoded key bytes, must not benull- Throws:
IllegalArgumentException- ifpkcs8isnull
-
-
Method Details
-
encoded
public byte[] encoded()Returns a defensive copy of the PKCS#8-encoded private 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-PRIV"pkcs8.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
pkcs8.b64with a base64-encoded key. Additional entries are ignored.- Parameters:
p- the pair sequence containing serialized fields- Returns:
- a reconstructed
XdhPrivateKeySpec - Throws:
IllegalArgumentException- ifpkcs8.b64is missing or cannot be decoded
-
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-