Class HqcPrivateKeySpec

java.lang.Object
zeroecho.core.alg.hqc.HqcPrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class HqcPrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable

HQC Private Key Specification

AlgorithmKeySpec wrapper for HQC private keys, encoded in standard PKCS#8 DER format.

This class is used to transport and import HQC private keys into the HqcAlgorithm. The encoded form is defensively copied on construction and retrieval and may be destroyed.

Serialization

marshal(HqcPrivateKeySpec) encodes the key material into a PairSeq with Base64 (unpadded) representation. The inverse unmarshal(PairSeq) restores the specification from such a sequence.

Security note

  • The contained byte array represents sensitive key material. Applications should minimize retention and ensure secure erasure when possible.
  • Use only for import into a trusted KeyFactory or HqcAlgorithm. Never log or transmit the raw array.

Usage example

// Wrap an existing PKCS#8 HQC private key
HqcPrivateKeySpec spec = new HqcPrivateKeySpec(pkcs8Bytes);

// Import into a PrivateKey via HqcAlgorithm
HqcAlgorithm hqc = new HqcAlgorithm();
PrivateKey priv = hqc.privateKeyImporter(HqcPrivateKeySpec.class).importPrivate(spec);

// Serialize for transport
PairSeq serialized = HqcPrivateKeySpec.marshal(spec);

// Reconstruct from serialized form
HqcPrivateKeySpec restored = HqcPrivateKeySpec.unmarshal(serialized);
Since:
1.0
  • Constructor Details

    • HqcPrivateKeySpec

      public HqcPrivateKeySpec(byte[] pkcs8Der)
      Constructs a new private key spec from a PKCS#8-encoded byte array.
      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-encoded key material.
      Returns:
      cloned PKCS#8 byte array
    • marshal

      public static PairSeq marshal(HqcPrivateKeySpec spec)
      Serializes this spec into a PairSeq with Base64-encoded key data.

      The resulting sequence has keys:

      • type = "HqcPrivateKeySpec"
      • pkcs8.b64 = Base64 of the PKCS#8 key
      Parameters:
      spec - the spec to serialize
      Returns:
      serialized representation in a PairSeq
    • unmarshal

      public static HqcPrivateKeySpec unmarshal(PairSeq p)
      Reconstructs a spec from its PairSeq representation.
      Parameters:
      p - sequence containing pkcs8.b64
      Returns:
      reconstructed HqcPrivateKeySpec
      Throws:
      IllegalArgumentException - if required field pkcs8.b64 is missing
    • toString

      public String toString()
      Returns a diagnostic string containing the encoded length.

      The actual key material is not exposed in this representation.

      Overrides:
      toString in class Object
      Returns:
      string with the PKCS#8 byte length
    • destroy

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

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