Class KyberPublicKeySpec

java.lang.Object
zeroecho.core.alg.kyber.KyberPublicKeySpec
All Implemented Interfaces:
AlgorithmKeySpec

public final class KyberPublicKeySpec extends Object implements AlgorithmKeySpec
Specification wrapper for a Kyber (ML-KEM) public key encoded in X.509.

Instances of this class carry an immutable copy of the X.509 SubjectPublicKeyInfo-encoded bytes. They are used with CryptoAlgorithm key builders to import keys into the provider’s native representation.

Encoding

  • Format: X.509 DER encoding of a Kyber public key (SubjectPublicKeyInfo).
  • Stored as a defensive clone to ensure immutability.
  • Marshalling/unmarshalling supported via PairSeq with Base64 encoding.

Usage

// Import a public key into a CryptoAlgorithm
byte[] x509Bytes = ...; // obtained from storage
KyberPublicKeySpec spec = new KyberPublicKeySpec(x509Bytes);
PublicKey k = kyberAlg.publicKeyImporter(KyberPublicKeySpec.class).importPublic(spec);

// Serialize for persistence
PairSeq seq = KyberPublicKeySpec.marshal(spec);

// Deserialize back
KyberPublicKeySpec restored = KyberPublicKeySpec.unmarshal(seq);

This class is immutable and thread-safe.

See Also:
  • Constructor Details

    • KyberPublicKeySpec

      public KyberPublicKeySpec(byte[] x509Der)
      Creates a new spec from X.509-encoded public key bytes.
      Parameters:
      x509Der - X.509 SubjectPublicKeyInfo DER-encoded public key, not null
      Throws:
      NullPointerException - if x509Der is null
  • Method Details

    • x509

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

      public static PairSeq marshal(KyberPublicKeySpec spec)
      Serializes this spec into a PairSeq using Base64 encoding.

      The sequence contains:

      • type = KyberPublicKey
      • x509.b64 = Base64 of X.509 bytes (no padding)
      Parameters:
      spec - the spec to marshal
      Returns:
      key-value representation suitable for persistence
    • unmarshal

      public static KyberPublicKeySpec unmarshal(PairSeq p)
      Reconstructs a KyberPublicKeySpec from a PairSeq.
      Parameters:
      p - key-value sequence containing an x509.b64 entry
      Returns:
      a new spec with decoded X.509 bytes
      Throws:
      IllegalArgumentException - if the required field is missing
    • toString

      public String toString()
      Returns a diagnostic string for logging and debugging.

      Does not expose key material; only length is shown.

      Overrides:
      toString in class Object
      Returns:
      string with length of encoded key