Class FrodoPrivateKeySpec
java.lang.Object
zeroecho.core.alg.frodo.FrodoPrivateKeySpec
- All Implemented Interfaces:
Destroyable, AlgorithmKeySpec
Specification for importing a Frodo private key
FrodoPrivateKeySpec is a simple wrapper around a PKCS#8-encoded
FrodoKEM private key. It provides defensive access to the raw encoding and
utilities for serialization.
Encoding format
- Keys are stored in the standard PKCS#8 DER format as produced by providers such as BouncyCastle PQC.
- The encoding is preserved exactly as given; no internal parsing or validation occurs in this class.
Usage
- Instances of this spec can be passed to
KeyBuilders.Asymmetric.importPrivate(String, AlgorithmKeySpec)to construct a usablePrivateKeyobject. - The
marshal(FrodoPrivateKeySpec)andunmarshal(PairSeq)helpers allow safe conversion to/from structured textual form for persistence or transmission.
// Import an existing Frodo private key
byte[] encoded = Files.readAllBytes(Paths.get("frodo.key"));
FrodoPrivateKeySpec spec = new FrodoPrivateKeySpec(encoded);
PrivateKey priv = session.keyBuilders().asymmetric().importPrivate("FrodoKEM", spec);
Thread-safety
The internal byte array is cloned on construction and when accessed via
pkcs8(). Access and destruction are synchronized.
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionFrodoPrivateKeySpec(byte[] pkcs8Der) Creates a new specification from a PKCS#8 DER-encoded key. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()booleanstatic PairSeqmarshal(FrodoPrivateKeySpec spec) Serializes this spec into aPairSeq, encoding the key as Base64 without padding.byte[]pkcs8()Returns a clone of the underlying PKCS#8 encoding.toString()Returns a diagnostic string containing the encoded length.static FrodoPrivateKeySpecParses aPairSeqpreviously produced bymarshal(FrodoPrivateKeySpec).
-
Constructor Details
-
FrodoPrivateKeySpec
public FrodoPrivateKeySpec(byte[] pkcs8Der) Creates a new specification from a PKCS#8 DER-encoded key.- Parameters:
pkcs8Der- the encoded private key bytes (will be cloned)- Throws:
NullPointerException- ifpkcs8Derisnull
-
-
Method Details
-
pkcs8
public byte[] pkcs8()Returns a clone of the underlying PKCS#8 encoding.- Returns:
- defensive copy of the PKCS#8-encoded private key
-
marshal
Serializes this spec into aPairSeq, encoding the key as Base64 without padding.- Parameters:
spec- Frodo private key specification to serialize- Returns:
- a
PairSeqwith type and Base64-encoded key
-
unmarshal
Parses aPairSeqpreviously produced bymarshal(FrodoPrivateKeySpec).- Parameters:
p- input sequence containing apkcs8.b64entry- Returns:
- a new private key spec initialized with the decoded bytes
- Throws:
IllegalArgumentException- ifpkcs8.b64entry is missing
-
toString
-
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-