Class CmcePrivateKeySpec

java.lang.Object
zeroecho.core.alg.cmce.CmcePrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class CmcePrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable

Classic McEliece (CMCE) private key specification

Wraps a CMCE private key in PKCS#8 (DER) encoding. This spec is used to import or serialize private keys into the ZeroEcho SPI.

The internal byte array is cloned on construction and on every accessor. Access and destruction are synchronized.

Marshalling

Example:

// Wrap an existing PKCS#8 byte array
CmcePrivateKeySpec spec = new CmcePrivateKeySpec(pkcs8Bytes);

// Serialize to PairSeq for storage or transport
PairSeq encoded = CmcePrivateKeySpec.marshal(spec);

// Reconstruct later
CmcePrivateKeySpec restored = CmcePrivateKeySpec.unmarshal(encoded);
Since:
1.0
  • Constructor Details

    • CmcePrivateKeySpec

      public CmcePrivateKeySpec(byte[] pkcs8Der)
      Creates a new specification from a PKCS#8-encoded CMCE private key.

      The input is defensively copied.

      Parameters:
      pkcs8Der - DER-encoded PKCS#8 private key
      Throws:
      NullPointerException - if pkcs8Der is null
  • Method Details

    • pkcs8

      public byte[] pkcs8()
      Returns a defensive copy of the PKCS#8 bytes.
      Returns:
      a fresh copy of the underlying PKCS#8 encoding
    • marshal

      public static PairSeq marshal(CmcePrivateKeySpec spec)
      Serializes the given private key spec into a PairSeq.

      The PKCS#8 bytes are Base64-encoded (without padding) and stored under the key "pkcs8.b64". The type tag "CmcePrivateKeySpec" is also included.

      Parameters:
      spec - the spec to serialize
      Returns:
      a PairSeq containing type and Base64-encoded key
      Throws:
      NullPointerException - if spec is null
    • unmarshal

      public static CmcePrivateKeySpec unmarshal(PairSeq p)
      Deserializes a CmcePrivateKeySpec from a PairSeq.

      The method scans for a key named "pkcs8.b64", decodes its value from Base64, and reconstructs the spec.

      Parameters:
      p - PairSeq containing serialized fields
      Returns:
      reconstructed CmcePrivateKeySpec
      Throws:
      IllegalArgumentException - if no "pkcs8.b64" field is found
    • toString

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

      The output is safe to log; it does not include key material.

      Overrides:
      toString in class Object
      Returns:
      a string in the form CmcePrivateKeySpec[len=N]
    • destroy

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

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