Class KyberPrivateKeySpec
java.lang.Object
zeroecho.core.alg.kyber.KyberPrivateKeySpec
- All Implemented Interfaces:
Destroyable, AlgorithmKeySpec
Specification wrapper for a Kyber (ML-KEM) private key encoded in PKCS#8.
Instances of this class carry an owned copy of the PKCS#8-encoded private key
bytes. They are used with CryptoAlgorithm key builders
to import keys into the provider’s native representation.
Encoding
- Format: PKCS#8 DER encoding of a Kyber private key.
- Stored as a defensive clone.
- Marshalling/unmarshalling supported via
PairSeqwith Base64 encoding.
Usage
// Import a private key into a CryptoAlgorithm
byte[] pkcs8Bytes = ...; // obtained from storage
KyberPrivateKeySpec spec = new KyberPrivateKeySpec(pkcs8Bytes);
PrivateKey k = kyberAlg.privateKeyImporter(KyberPrivateKeySpec.class).importPrivate(spec);
// Serialize for persistence
PairSeq seq = KyberPrivateKeySpec.marshal(spec);
// Deserialize back
KyberPrivateKeySpec restored = KyberPrivateKeySpec.unmarshal(seq);
Access and destruction are synchronized.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionKyberPrivateKeySpec(byte[] pkcs8Der) Creates a new spec from PKCS#8-encoded private key bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()booleanstatic PairSeqmarshal(KyberPrivateKeySpec spec) Serializes this spec into aPairSequsing Base64 encoding.byte[]pkcs8()Returns a defensive copy of the PKCS#8-encoded private key.toString()Returns a diagnostic string for logging and debugging.static KyberPrivateKeySpecReconstructs aKyberPrivateKeySpecfrom aPairSeq.
-
Constructor Details
-
KyberPrivateKeySpec
public KyberPrivateKeySpec(byte[] pkcs8Der) Creates a new spec from PKCS#8-encoded private key bytes.- Parameters:
pkcs8Der- PKCS#8 DER-encoded private key, not null- Throws:
NullPointerException- ifpkcs8Deris null
-
-
Method Details
-
pkcs8
public byte[] pkcs8()Returns a defensive copy of the PKCS#8-encoded private key.- Returns:
- cloned byte array of PKCS#8 DER encoding
-
marshal
Serializes this spec into aPairSequsing Base64 encoding.The sequence contains:
type=KyberPrivateKeypkcs8.b64= Base64 of PKCS#8 bytes (no padding)
- Parameters:
spec- the spec to marshal- Returns:
- key-value representation suitable for persistence
-
unmarshal
Reconstructs aKyberPrivateKeySpecfrom aPairSeq.- Parameters:
p- key-value sequence containing apkcs8.b64entry- Returns:
- a new spec with decoded PKCS#8 bytes
- Throws:
IllegalArgumentException- if the required field is missing
-
toString
-
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceDestroyable
-