Class SntruPrimePublicKeySpec

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

public final class SntruPrimePublicKeySpec extends Object implements AlgorithmKeySpec
Specification wrapper for an encoded SNTRU Prime public key in X.509 format.

SntruPrimePublicKeySpec provides a type-safe holder for X.509 SubjectPublicKeyInfo bytes belonging to the SNTRU Prime 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("sntru-public.spki"));
SntruPrimePublicKeySpec spec = new SntruPrimePublicKeySpec(der);

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

Serialization

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

    • SntruPrimePublicKeySpec

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

      The result contains:

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

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