Class SaberPrivateKeySpec

java.lang.Object
zeroecho.core.alg.saber.SaberPrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class SaberPrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable
Encoded private key specification for the SABER post-quantum KEM algorithm.

A SaberPrivateKeySpec wraps a SABER private key in standard PKCS#8 format. It provides safe accessors for cloning, along with serialization helpers to marshal and unmarshal from a compact PairSeq representation.

Lifecycle

The internal PKCS#8 encoding is defensively copied on construction and on retrieval via pkcs8(). Access and destruction are synchronized.

Usage example

// Import SABER private key from encoded form
byte[] pkcs8Bytes = ...;
SaberPrivateKeySpec spec = new SaberPrivateKeySpec(pkcs8Bytes);
PrivateKey key = session.keyBuilders().asymmetric().importPrivate("SABER", spec);
  • Constructor Details

    • SaberPrivateKeySpec

      public SaberPrivateKeySpec(byte[] pkcs8Der)
      Constructs a private key specification from a PKCS#8-encoded SABER private key.
      Parameters:
      pkcs8Der - the PKCS#8-encoded private key bytes (DER format)
      Throws:
      NullPointerException - if pkcs8Der is null
  • Method Details

    • pkcs8

      public byte[] pkcs8()
      Returns a defensive copy of the PKCS#8-encoded private key.
      Returns:
      cloned byte array containing the PKCS#8 encoding
    • marshal

      public static PairSeq marshal(SaberPrivateKeySpec spec)
      Serializes this specification into a compact PairSeq form.

      The encoding includes:

      • type = SaberPrivateKeySpec
      • pkcs8.b64 = Base64 encoding of the PKCS#8 bytes (no padding)
      Parameters:
      spec - the private key specification to serialize
      Returns:
      a PairSeq containing the encoded data
      Throws:
      NullPointerException - if spec is null
    • unmarshal

      public static SaberPrivateKeySpec unmarshal(PairSeq p)
      Deserializes a SaberPrivateKeySpec from its PairSeq form.

      The sequence must contain a field pkcs8.b64 with the Base64-encoded PKCS#8 private key bytes. If the field is missing, an exception is thrown.

      Parameters:
      p - the pair sequence to parse
      Returns:
      a reconstructed SaberPrivateKeySpec
      Throws:
      IllegalArgumentException - if the pkcs8.b64 field is missing
    • toString

      public String toString()
      Returns a diagnostic string showing the length of the encoded key.

      This string does not expose the key material itself and is safe for logs.

      Overrides:
      toString in class Object
      Returns:
      string representation of this spec, including encoded length
    • destroy

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

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