Class Ed25519PrivateKeySpec

java.lang.Object
zeroecho.core.alg.ed25519.Ed25519PrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class Ed25519PrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable

Specification for Ed25519 private keys

AlgorithmKeySpec representing an Ed25519 private key in its encoded PKCS#8 form.

This spec is used by Ed25519PrivateKeyBuilder and related APIs to import and wrap Ed25519 private keys. The encoding is expected to conform to the PKCS#8 standard as produced by standard JCA key factories or external tooling.

Responsibilities

Usage example

// Wrap PKCS#8 bytes in a spec
Ed25519PrivateKeySpec spec = new Ed25519PrivateKeySpec(pkcs8Bytes);

// Import into a PrivateKey using ZeroEcho
PrivateKey priv = session.keyBuilders().asymmetric().importPrivate("Ed25519", spec);

// Serialize to PairSeq (e.g., for configuration or transport)
PairSeq seq = Ed25519PrivateKeySpec.marshal(spec);

// Reconstruct from serialized form
Ed25519PrivateKeySpec restored = Ed25519PrivateKeySpec.unmarshal(seq);

Thread-safety

Access and destruction are synchronized. The internal key bytes are defensively copied on construction and retrieval.
Since:
1.0
  • Constructor Details

    • Ed25519PrivateKeySpec

      public Ed25519PrivateKeySpec(byte[] encodedPkcs8)
      Creates a new Ed25519 private key specification from its PKCS#8 encoding.
      Parameters:
      encodedPkcs8 - PKCS#8-encoded private key bytes; must not be null
      Throws:
      IllegalArgumentException - if encodedPkcs8 is null
  • Method Details

    • encoded

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

      public static PairSeq marshal(Ed25519PrivateKeySpec spec)
      Serializes the given private key spec to a base64-encoded PairSeq.

      The output includes a type marker ("Ed25519-PRIV") and the field "pkcs8.b64" containing the base64 representation of the key.

      Parameters:
      spec - private key spec to marshal
      Returns:
      serialized representation as a PairSeq
    • unmarshal

      public static Ed25519PrivateKeySpec unmarshal(PairSeq p)
      Reconstructs a private key spec from a base64-encoded PairSeq.

      The sequence must contain the field "pkcs8.b64" with the base64 encoding of the PKCS#8 key.

      Parameters:
      p - serialized key data
      Returns:
      a new Ed25519PrivateKeySpec instance
      Throws:
      IllegalArgumentException - if the sequence does not contain "pkcs8.b64"
    • destroy

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

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