Class SntruPrimePrivateKeySpec

java.lang.Object
zeroecho.core.alg.ntruprime.SntruPrimePrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class SntruPrimePrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable
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 usable PrivateKey.
// 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 via PairSeq:
Since:
1.0
  • 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 - if pkcs8Der is 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

      public static PairSeq marshal(SntruPrimePrivateKeySpec spec)
      Serializes this specification into a PairSeq.

      The result contains:

      • type = "SntruPrimePrivateKeySpec"
      • pkcs8.b64 = ... base64-encoded key
      Parameters:
      spec - specification to marshal
      Returns:
      serialized representation containing the base64-encoded key
    • unmarshal

      public static SntruPrimePrivateKeySpec unmarshal(PairSeq p)
      Reconstructs a private key specification from a PairSeq.

      The sequence must contain a pkcs8.b64 entry; otherwise an IllegalArgumentException is thrown.

      Parameters:
      p - serialized pair sequence produced by marshal(SntruPrimePrivateKeySpec)
      Returns:
      a new specification with the decoded PKCS#8 bytes
      Throws:
      IllegalArgumentException - if the required field is missing
    • toString

      public String toString()
      Returns a diagnostic string identifying this specification.

      The string includes the encoded key length but never the key material.

      Overrides:
      toString in class Object
      Returns:
      a string such as "SntruPrimePrivateKeySpec[len=1234]"
    • destroy

      public void destroy()
      Specified by:
      destroy in interface Destroyable
    • isDestroyed

      public boolean isDestroyed()
      Specified by:
      isDestroyed in interface Destroyable