Class SntruPrimePrivateKeySpec
java.lang.Object
zeroecho.core.alg.ntruprime.SntruPrimePrivateKeySpec
- All Implemented Interfaces:
Destroyable, AlgorithmKeySpec
Specification wrapper for an encoded SNTRU Prime private key in PKCS#8
format.
SntruPrimePrivateKeySpec provides a type-safe holder for
PKCS#8-encoded private key material belonging to the SNTRU Prime KEM. It is
destroyable, and defensive copies are made on construction and retrieval.
Usage
Instances are typically created after parsing or receiving encoded key data, and passed to an algorithm’s key builder to import a usablePrivateKey.
// Wrap existing encoded key
byte[] pkcs8 = Files.readAllBytes(Paths.get("sntru-private.pk8"));
SntruPrimePrivateKeySpec spec = new SntruPrimePrivateKeySpec(pkcs8);
// Import via CryptoAlgorithms
PrivateKey priv = session.keyBuilders().asymmetric().importPrivate("SNTRUPrime", spec);
Serialization
A lightweight marshaling format is supported viaPairSeq:
marshal(SntruPrimePrivateKeySpec)produces a base64 string under the key"pkcs8.b64".unmarshal(PairSeq)reconstructs a new spec instance from such a sequence.
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionSntruPrimePrivateKeySpec(byte[] pkcs8Der) Constructs a new private key specification from a PKCS#8-encoded byte array. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()booleanstatic PairSeqSerializes this specification into aPairSeq.byte[]pkcs8()Returns a clone of the PKCS#8-encoded private key bytes.toString()Returns a diagnostic string identifying this specification.static SntruPrimePrivateKeySpecReconstructs a private key specification from aPairSeq.
-
Constructor Details
-
SntruPrimePrivateKeySpec
public SntruPrimePrivateKeySpec(byte[] pkcs8Der) Constructs a new private key specification from a PKCS#8-encoded byte array.A defensive copy is made; the input array may be reused or modified without affecting this instance.
- Parameters:
pkcs8Der- PKCS#8 encoded private key bytes (DER form)- Throws:
NullPointerException- ifpkcs8Deris null
-
-
Method Details
-
pkcs8
public byte[] pkcs8()Returns a clone of the PKCS#8-encoded private key bytes.- Returns:
- copy of the encoded private key
-
marshal
Serializes this specification into aPairSeq.The result contains:
type = "SntruPrimePrivateKeySpec"pkcs8.b64 = ...base64-encoded key
- Parameters:
spec- specification to marshal- Returns:
- serialized representation containing the base64-encoded key
-
unmarshal
Reconstructs a private key specification from aPairSeq.The sequence must contain a
pkcs8.b64entry; otherwise anIllegalArgumentExceptionis thrown.- Parameters:
p- serialized pair sequence produced bymarshal(SntruPrimePrivateKeySpec)- Returns:
- a new specification with the 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
-