Class NtrulPrimePublicKeySpec

java.lang.Object
zeroecho.core.alg.ntruprime.NtrulPrimePublicKeySpec
All Implemented Interfaces:
AlgorithmKeySpec

public final class NtrulPrimePublicKeySpec extends Object implements AlgorithmKeySpec
Specification wrapper for an encoded NTRU LPRime public key in X.509 format.

NtrulPrimePublicKeySpec provides a type-safe holder for X.509 SubjectPublicKeyInfo bytes belonging to the NTRU LPRime KEM. It is immutable 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 PublicKey.
// Wrap existing encoded public key
byte[] der = Files.readAllBytes(Paths.get("ntru-public.spki"));
NtrulPrimePublicKeySpec spec = new NtrulPrimePublicKeySpec(der);

// Import via CryptoAlgorithms
PublicKey pub = session.keyBuilders().asymmetric().importPublic("NTRULPRime", spec);

Serialization

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

    • NtrulPrimePublicKeySpec

      public NtrulPrimePublicKeySpec(byte[] x509Der)
      Constructs a new public key specification from an X.509-encoded byte array.

      A defensive copy is made; the input array may be reused or modified without affecting this instance.

      Parameters:
      x509Der - X.509 SubjectPublicKeyInfo bytes
      Throws:
      NullPointerException - if x509Der is null
  • Method Details

    • x509

      public byte[] x509()
      Returns a clone of the X.509-encoded public key bytes.
      Returns:
      copy of the encoded public key
    • marshal

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

      The result contains:

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

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

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

      Parameters:
      p - serialized pair sequence produced by marshal(NtrulPrimePublicKeySpec)
      Returns:
      a new specification with the decoded X.509 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 "NtrulPrimePublicKeySpec[len=1234]"