Class KyberPrivateKeySpec

java.lang.Object
zeroecho.core.alg.kyber.KyberPrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class KyberPrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable
Specification wrapper for a Kyber (ML-KEM) private key encoded in PKCS#8.

Instances of this class carry an owned copy of the PKCS#8-encoded private key bytes. They are used with CryptoAlgorithm key builders to import keys into the provider’s native representation.

Encoding

  • Format: PKCS#8 DER encoding of a Kyber private key.
  • Stored as a defensive clone.
  • Marshalling/unmarshalling supported via PairSeq with Base64 encoding.

Usage

// Import a private key into a CryptoAlgorithm
byte[] pkcs8Bytes = ...; // obtained from storage
KyberPrivateKeySpec spec = new KyberPrivateKeySpec(pkcs8Bytes);
PrivateKey k = kyberAlg.privateKeyImporter(KyberPrivateKeySpec.class).importPrivate(spec);

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

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

Access and destruction are synchronized.

See Also:
  • Constructor Details

    • KyberPrivateKeySpec

      public KyberPrivateKeySpec(byte[] pkcs8Der)
      Creates a new spec from PKCS#8-encoded private key bytes.
      Parameters:
      pkcs8Der - PKCS#8 DER-encoded private key, not null
      Throws:
      NullPointerException - if pkcs8Der is null
  • Method Details

    • pkcs8

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

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

      The sequence contains:

      • type = KyberPrivateKey
      • pkcs8.b64 = Base64 of PKCS#8 bytes (no padding)
      Parameters:
      spec - the spec to marshal
      Returns:
      key-value representation suitable for persistence
    • unmarshal

      public static KyberPrivateKeySpec unmarshal(PairSeq p)
      Reconstructs a KyberPrivateKeySpec from a PairSeq.
      Parameters:
      p - key-value sequence containing a pkcs8.b64 entry
      Returns:
      a new spec with decoded PKCS#8 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
    • destroy

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

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