Class AbstractEncodedPrivateKeyBuilder<S extends AlgorithmKeySpec>

java.lang.Object
zeroecho.core.alg.common.eddsa.AbstractEncodedPrivateKeyBuilder<S>
Type Parameters:
S - the algorithm-specific key specification carrying PKCS#8 data
All Implemented Interfaces:
PrivateKeyImporter<S>
Direct Known Subclasses:
Ed25519PrivateKeyBuilder, Ed448PrivateKeyBuilder

public abstract class AbstractEncodedPrivateKeyBuilder<S extends AlgorithmKeySpec> extends Object implements PrivateKeyImporter<S>

Abstract EdDSA Encoded Private Key Builder

Base class for reconstructing EdDSA private keys (e.g., Ed25519, Ed448) from PKCS#8-encoded specifications.

Unlike AbstractEdDSAKeyGenBuilder, which is responsible for generating fresh key pairs, this class focuses on importing existing private keys from their encoded representation. Public key import and key pair generation are deliberately unsupported here.

Responsibilities

Thread-safety

Stateless and safe for concurrent use. Each import operation creates a new KeyFactory instance internally.
Since:
1.0
  • Constructor Details

    • AbstractEncodedPrivateKeyBuilder

      public AbstractEncodedPrivateKeyBuilder()
      Creates a stateless encoded-private-key importer base.
  • Method Details

    • jcaKeyFactoryAlg

      protected abstract String jcaKeyFactoryAlg()
      Returns the canonical JCA algorithm identifier used by KeyFactory.getInstance(String).

      Must be one of the algorithm names recognized by the JDK (e.g., "Ed25519", "Ed448").

      Returns:
      the JCA algorithm identifier string
    • encodedPkcs8

      protected abstract byte[] encodedPkcs8(S spec)
      Extracts the raw PKCS#8-encoded private key bytes from the given spec.

      Subclasses must implement this to pull the encoded material from their AlgorithmKeySpec representation.

      Parameters:
      spec - algorithm-specific key specification
      Returns:
      PKCS#8-encoded private key bytes
    • importPrivate

      public PrivateKey importPrivate(S spec) throws GeneralSecurityException
      Imports an EdDSA private key from its PKCS#8-encoded form.

      This method uses KeyFactory initialized with the algorithm returned by jcaKeyFactoryAlg() to parse the bytes provided by encodedPkcs8(AlgorithmKeySpec).

      Specified by:
      importPrivate in interface PrivateKeyImporter<S extends AlgorithmKeySpec>
      Parameters:
      spec - algorithm-specific key specification containing PKCS#8 bytes
      Returns:
      a reconstructed PrivateKey instance
      Throws:
      GeneralSecurityException - if the key material is invalid or the JCA provider does not support the algorithm