Class AbstractEncodedPublicKeyBuilder<S extends AlgorithmKeySpec>

java.lang.Object
zeroecho.core.alg.common.eddsa.AbstractEncodedPublicKeyBuilder<S>
Type Parameters:
S - the algorithm-specific key specification carrying X.509 data
All Implemented Interfaces:
PublicKeyImporter<S>
Direct Known Subclasses:
Ed25519PublicKeyBuilder, Ed448PublicKeyBuilder

public abstract class AbstractEncodedPublicKeyBuilder<S extends AlgorithmKeySpec> extends Object implements PublicKeyImporter<S>

Abstract EdDSA Encoded Public Key Builder

Base class for reconstructing EdDSA public keys (e.g., Ed25519, Ed448) from X.509-encoded specifications.

Unlike AbstractEdDSAKeyGenBuilder, which generates new key pairs, and AbstractEncodedPrivateKeyBuilder, which restores private keys, this class focuses exclusively on importing existing public keys from their encoded form. Key pair generation and private key import are intentionally unsupported here.

Responsibilities

Thread-safety

Stateless and safe for concurrent use. Each call to importPublic(AlgorithmKeySpec) creates a new KeyFactory.
Since:
1.0
  • Constructor Details

    • AbstractEncodedPublicKeyBuilder

      public AbstractEncodedPublicKeyBuilder()
      Creates a stateless encoded-public-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
    • encodedX509

      protected abstract byte[] encodedX509(S spec)
      Extracts the raw X.509-encoded public 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:
      X.509-encoded public key bytes
    • importPublic

      public PublicKey importPublic(S spec) throws GeneralSecurityException
      Imports an EdDSA public key from its X.509-encoded form.

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

      Specified by:
      importPublic in interface PublicKeyImporter<S extends AlgorithmKeySpec>
      Parameters:
      spec - algorithm-specific key specification containing X.509 bytes
      Returns:
      a reconstructed PublicKey instance
      Throws:
      GeneralSecurityException - if the key material is invalid or the JCA provider does not support the algorithm