Class HqcPublicKeySpec

java.lang.Object
zeroecho.core.alg.hqc.HqcPublicKeySpec
All Implemented Interfaces:
AlgorithmKeySpec

public final class HqcPublicKeySpec extends Object implements AlgorithmKeySpec

HQC Public Key Specification

AlgorithmKeySpec wrapper for HQC public keys, encoded in standard X.509 DER format.

This class is used to transport and import HQC public keys into the HqcAlgorithm. The encoded form is immutable and defensively copied on construction and retrieval.

Serialization

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

Security note

  • Public keys are not confidential, but integrity is critical. They should only be distributed over authenticated or integrity-protected channels.
  • The contained byte array is immutable and returned as a defensive copy to avoid accidental modification.

Usage example


 // Wrap an existing X.509 HQC public key
 HqcPublicKeySpec spec = new HqcPublicKeySpec(x509Bytes);

 // Import into a PublicKey via HqcAlgorithm
 HqcAlgorithm hqc = new HqcAlgorithm();
 PublicKey pub = hqc.importPublic(spec);

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

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

    • HqcPublicKeySpec

      public HqcPublicKeySpec(byte[] x509Der)
      Constructs a new public key spec from an X.509-encoded byte array.
      Parameters:
      x509Der - DER-encoded X.509 public key
      Throws:
      NullPointerException - if x509Der is null
  • Method Details

    • x509

      public byte[] x509()
      Returns a defensive copy of the X.509-encoded key material.
      Returns:
      cloned X.509 byte array
    • marshal

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

      The resulting sequence has keys:

      • type = "HqcPublicKeySpec"
      • x509.b64 = Base64 of the X.509 key
      Parameters:
      spec - the spec to serialize
      Returns:
      serialized representation in a PairSeq
    • unmarshal

      public static HqcPublicKeySpec unmarshal(PairSeq p)
      Reconstructs a spec from its PairSeq representation.
      Parameters:
      p - sequence containing x509.b64
      Returns:
      reconstructed HqcPublicKeySpec
      Throws:
      IllegalArgumentException - if required field x509.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 X.509 byte length