Class NtrulPrimePrivateKeySpec

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

public final class NtrulPrimePrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable
Specification wrapper for an encoded NTRU LPRime private key in PKCS#8 format.

NtrulPrimePrivateKeySpec provides a type-safe holder for PKCS#8-encoded private key material belonging to the NTRU LPRime 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("ntru-private.pk8"));
NtrulPrimePrivateKeySpec spec = new NtrulPrimePrivateKeySpec(pkcs8);

// Import via CryptoAlgorithms
PrivateKey priv = session.keyBuilders().asymmetric().importPrivate("NTRULPRime", spec);

Serialization

A lightweight marshaling format is supported via PairSeq:
Since:
1.0
  • Constructor Details

    • NtrulPrimePrivateKeySpec

      public NtrulPrimePrivateKeySpec(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(NtrulPrimePrivateKeySpec spec)
      Serializes this specification into a PairSeq.

      The result contains:

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

      public static NtrulPrimePrivateKeySpec 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(NtrulPrimePrivateKeySpec)
      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 "NtrulPrimePrivateKeySpec[len=1234]"
    • destroy

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

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