Class EcdsaPrivateKeySpec

java.lang.Object
zeroecho.core.alg.ecdsa.EcdsaPrivateKeySpec
All Implemented Interfaces:
Destroyable, AlgorithmKeySpec

public final class EcdsaPrivateKeySpec extends Object implements AlgorithmKeySpec, Destroyable

ECDSA Private Key Specification

A destroyable wrapper around a PKCS#8-encoded ECDSA private key. This specification is used by EcdsaPrivateKeyBuilder to import keys into the JCA PrivateKey representation.

Encoding

  • Keys are stored internally in PKCS#8 DER format.
  • Instances are defensive: the internal byte array is cloned on construction and on every access.
  • For serialization, marshal(EcdsaPrivateKeySpec) encodes the PKCS#8 bytes in Base64 without padding.

Usage

// Construct from PKCS#8 DER
byte[] pkcs8 = ...; // load from file or keystore
EcdsaPrivateKeySpec spec = new EcdsaPrivateKeySpec(pkcs8);

// Import into a PrivateKey
PrivateKey priv = new EcdsaPrivateKeyBuilder().importPrivate(spec);

// Marshal/unmarshal for transport or storage
PairSeq seq = EcdsaPrivateKeySpec.marshal(spec);
EcdsaPrivateKeySpec restored = EcdsaPrivateKeySpec.unmarshal(seq);
Since:
1.0
  • Constructor Details

    • EcdsaPrivateKeySpec

      public EcdsaPrivateKeySpec(byte[] pkcs8)
      Creates a new private key specification from a PKCS#8 encoded byte array.
      Parameters:
      pkcs8 - PKCS#8 DER-encoded private key (must not be null)
      Throws:
      IllegalArgumentException - if pkcs8 is null
  • Method Details

    • encoded

      public byte[] encoded()
      Returns a defensive copy of the encoded PKCS#8 data.
      Returns:
      cloned PKCS#8 byte array
    • marshal

      public static PairSeq marshal(EcdsaPrivateKeySpec spec)
      Serializes this specification into a PairSeq.

      The PKCS#8 data is Base64-encoded (without padding) and emitted with the key "pkcs8.b64".

      Parameters:
      spec - private key spec to marshal
      Returns:
      serialized representation in key-value form
    • unmarshal

      public static EcdsaPrivateKeySpec unmarshal(PairSeq p)
      Reconstructs a private key specification from a PairSeq.

      The sequence must contain a "pkcs8.b64" field with Base64-encoded PKCS#8 DER data. If missing, an IllegalArgumentException is thrown.

      Parameters:
      p - serialized key-value sequence
      Returns:
      reconstructed EcdsaPrivateKeySpec
      Throws:
      IllegalArgumentException - if pkcs8.b64 is absent
    • destroy

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

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