This class provides the bridge between EdDSA-specific key specifications and the standard Java Cryptography Architecture (JCA) KeyFactory interface. It enables conversion between different key representations and supports standard encoding formats for interoperability.
Supported Operations:
- Key Generation: Create EdDSA keys from specifications
- Key Conversion: Translate between different key formats
- Standard Encoding: Support for PKCS#8 and X.509 formats
- Key Specification: Extract key parameters from existing keys
Supported Key Specifications:
EdDSAPublicKeySpec- EdDSA-specific public key specificationEdDSAPrivateKeySpec- EdDSA-specific private key specificationPKCS8EncodedKeySpec- Standard PKCS#8 private key encoding (since 0.9.25)X509EncodedKeySpec- Standard X.509 public key encoding (since 0.9.25)
Usage Example:
// Create KeyFactory instance
KeyFactory keyFactory = KeyFactory.getInstance("EdDSA", "I2P");
// Generate public key from specification
EdDSAPublicKeySpec pubSpec = new EdDSAPublicKeySpec(publicPoint, curveParams);
EdDSAPublicKey publicKey = (EdDSAPublicKey) keyFactory.generatePublic(pubSpec);
// Convert to standard X.509 format
X509EncodedKeySpec x509Spec = keyFactory.getKeySpec(publicKey, X509EncodedKeySpec.class);
Thread Safety: This class is thread-safe and can be used concurrently by multiple threads. Key objects created by this factory are immutable and thread-safe.
Security Considerations:
- Private key material is handled securely during conversion
- Standard encoding formats ensure interoperability with other providers
- Key validation is performed during specification conversion
Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionprotected PrivateKeyengineGeneratePrivate(KeySpec keySpec) Generates an EdDSA private key from the provided key specification.protected PublicKeyengineGeneratePublic(KeySpec keySpec) Generates an EdDSA public key from the provided key specification.protected <T extends KeySpec>
TengineGetKeySpec(Key key, Class<T> keySpec) Returns a specification (key material) of the given key object.protected KeyengineTranslateKey(Key key) Translates a key object from one provider to another.
Constructor Details
KeyFactory
public KeyFactory()Constructor. Key specifications are converted on each call and nothing is retained between calls, so a bare instance is a complete factory.
Method Details
engineGeneratePrivate
Generates an EdDSA private key from the provided key specification.This method converts various key specification formats into EdDSA private keys, supporting both EdDSA-specific specifications and, since 0.9.25, standard
PKCS8EncodedKeySpecencoding.- Specified by:
engineGeneratePrivatein classKeyFactorySpi- Parameters:
keySpec- the key specification to convert- Returns:
- the generated EdDSA private key
- Throws:
InvalidKeySpecException- if the key specification is unsupported or malformed
engineGeneratePublic
Generates an EdDSA public key from the provided key specification.This method converts various key specification formats into EdDSA public keys, supporting both EdDSA-specific specifications and, since 0.9.25, standard
X509EncodedKeySpecencoding.- Specified by:
engineGeneratePublicin classKeyFactorySpi- Parameters:
keySpec- the key specification to convert- Returns:
- the generated EdDSA public key
- Throws:
InvalidKeySpecException- if the key specification is unsupported or malformed
engineGetKeySpec
protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException Returns a specification (key material) of the given key object.This method extracts the underlying key parameters from EdDSA keys and converts them into the requested specification format.
- Specified by:
engineGetKeySpecin classKeyFactorySpi- Type Parameters:
T- the type of the returned key specification- Parameters:
key- the EdDSA key whose parameters are to be extractedkeySpec- the requested specification class- Returns:
- the corresponding key specification
- Throws:
InvalidKeySpecException- if the requested specification type is unsupported or the key cannot be converted
engineTranslateKey
Translates a key object from one provider to another.This method would allow conversion between EdDSA keys from different security providers, but currently no other EdDSA providers are known or supported in the I2P environment.
- Specified by:
engineTranslateKeyin classKeyFactorySpi- Parameters:
key- the key that would be translated; no translation is implemented- Returns:
- the translated key
- Throws:
InvalidKeyException- always, as no other EdDSA providers are supported