Class FrodoPrivateKeySpec

java.lang.Object
zeroecho.core.alg.frodo.FrodoPrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class FrodoPrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable

Specification for importing a Frodo private key

FrodoPrivateKeySpec is a simple wrapper around a PKCS#8-encoded FrodoKEM private key. It provides defensive access to the raw encoding and utilities for serialization.

Encoding format

  • Keys are stored in the standard PKCS#8 DER format as produced by providers such as BouncyCastle PQC.
  • The encoding is preserved exactly as given; no internal parsing or validation occurs in this class.

Usage

// Import an existing Frodo private key
byte[] encoded = Files.readAllBytes(Paths.get("frodo.key"));
FrodoPrivateKeySpec spec = new FrodoPrivateKeySpec(encoded);
PrivateKey priv = session.keyBuilders().asymmetric().importPrivate("FrodoKEM", spec);

Thread-safety

The internal byte array is cloned on construction and when accessed via pkcs8(). Access and destruction are synchronized.

Since:
1.0
  • Constructor Details

    • FrodoPrivateKeySpec

      public FrodoPrivateKeySpec(byte[] pkcs8Der)
      Creates a new specification from a PKCS#8 DER-encoded key.
      Parameters:
      pkcs8Der - the encoded private key bytes (will be cloned)
      Throws:
      NullPointerException - if pkcs8Der is null
  • Method Details

    • pkcs8

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

      public static PairSeq marshal(FrodoPrivateKeySpec spec)
      Serializes this spec into a PairSeq, encoding the key as Base64 without padding.
      Parameters:
      spec - Frodo private key specification to serialize
      Returns:
      a PairSeq with type and Base64-encoded key
    • unmarshal

      public static FrodoPrivateKeySpec unmarshal(PairSeq p)
      Parses a PairSeq previously produced by marshal(FrodoPrivateKeySpec).
      Parameters:
      p - input sequence containing a pkcs8.b64 entry
      Returns:
      a new private key spec initialized with the decoded bytes
      Throws:
      IllegalArgumentException - if pkcs8.b64 entry is missing
    • toString

      public String toString()
      Returns a diagnostic string containing the encoded length.
      Overrides:
      toString in class Object
      Returns:
      string in the form FrodoPrivateKeySpec[len=N]
    • destroy

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

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