public final class KeyFactory extends KeyFactorySpi
Supported Operations:
Supported Key Specifications:
ElGamalPublicKeySpec - ElGamal-specific public key specificationElGamalPrivateKeySpec - ElGamal-specific private key specificationPKCS8EncodedKeySpec - Standard PKCS#8 private key encodingX509EncodedKeySpec - Standard X.509 public key encodingUsage Example:
// Create KeyFactory instance
KeyFactory keyFactory = KeyFactory.getInstance("ElGamal", "I2P");
// Generate private key from specification
ElGamalParameterSpec params = new ElGamalParameterSpec(p, g);
ElGamalPrivateKeySpec privSpec = new ElGamalPrivateKeySpec(privateKey, params);
ElGamalPrivateKey privateKey = (ElGamalPrivateKey) keyFactory.generatePrivate(privSpec);
// Convert to standard PKCS#8 format
PKCS8EncodedKeySpec pkcs8Spec = keyFactory.getKeySpec(privateKey, PKCS8EncodedKeySpec.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:
KeyFactory,
ElGamalPublicKey,
ElGamalPrivateKey,
I2PProvider| Constructor and Description |
|---|
KeyFactory() |
| Modifier and Type | Method and Description |
|---|---|
protected PrivateKey |
engineGeneratePrivate(KeySpec keySpec)
Generates an ElGamal private key from the provided key specification.
|
protected PublicKey |
engineGeneratePublic(KeySpec keySpec)
Generates an ElGamal public key from the provided key specification.
|
protected <T extends KeySpec> |
engineGetKeySpec(Key key,
Class<T> keySpec)
Returns a specification (key material) of the given key object.
|
protected Key |
engineTranslateKey(Key key)
Translates a key object from one provider to another.
|
protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException
engineGeneratePrivate in class KeyFactorySpikeySpec - the key specification to convertInvalidKeySpecException - if the key specification is unsupported or malformedprotected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException
engineGeneratePublic in class KeyFactorySpikeySpec - the key specification to convertInvalidKeySpecException - if the key specification is unsupported or malformedprotected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException
engineGetKeySpec in class KeyFactorySpiT - the type of the returned key specificationkey - the key to convertkeySpec - the requested specification classInvalidKeySpecException - if the requested specification type is unsupported
or the key cannot be convertedprotected Key engineTranslateKey(Key key) throws InvalidKeyException
engineTranslateKey in class KeyFactorySpikey - the key to translateInvalidKeyException - always, as no other ElGamal providers are supported