public class KeyFactory extends Object
KeyFactory is an engine class that can be used to translate between
public and private key objects and convert keys between their external
representation, that can be easily transported and their internal
representation.| Modifier | Constructor and Description |
|---|---|
protected |
KeyFactory(KeyFactorySpi keyFacSpi,
Provider provider,
String algorithm)
Constructs a new instance of
KeyFactory with the specified
arguments. |
| Modifier and Type | Method and Description |
|---|---|
PrivateKey |
generatePrivate(KeySpec keySpec)
Generates a instance of
PrivateKey from the given key
specification. |
PublicKey |
generatePublic(KeySpec keySpec)
Generates a instance of
PublicKey from the given key
specification. |
String |
getAlgorithm()
Returns the name of the algorithm associated with this
KeyFactory. |
static KeyFactory |
getInstance(String algorithm)
Returns a new instance of
KeyFactory that utilizes the specified
algorithm. |
static KeyFactory |
getInstance(String algorithm,
Provider provider)
Returns a new instance of
KeyFactory that utilizes the specified
algorithm from the specified provider. |
static KeyFactory |
getInstance(String algorithm,
String provider)
Returns a new instance of
KeyFactory that utilizes the specified
algorithm from the specified provider. |
<T extends KeySpec> |
getKeySpec(Key key,
Class<T> keySpec)
Returns the key specification for the specified key.
|
Provider |
getProvider()
Returns the provider associated with this
KeyFactory. |
Key |
translateKey(Key key)
Translates the given key into a key from this key factory.
|
protected KeyFactory(KeyFactorySpi keyFacSpi, Provider provider, String algorithm)
KeyFactory with the specified
arguments.keyFacSpi - the concrete key factory service.provider - the provider.algorithm - the algorithm to use.public static KeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException
KeyFactory that utilizes the specified
algorithm.algorithm - the name of the algorithm.KeyFactory that utilizes the specified
algorithm.NoSuchAlgorithmException - if no provider provides the requested algorithm.public static KeyFactory getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
KeyFactory that utilizes the specified
algorithm from the specified provider.algorithm - the name of the algorithm.provider - the name of the provider.KeyFactory that utilizes the specified
algorithm from the specified provider.NoSuchAlgorithmException - if the provider does not provide the requested algorithm.NoSuchProviderException - if the requested provider is not available.IllegalArgumentException - if provider == null || provider.isEmpty()public static KeyFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
KeyFactory that utilizes the specified
algorithm from the specified provider. The provider supplied
does not have to be registered.algorithm - the name of the algorithm.provider - the security provider.KeyFactory that utilizes the specified
algorithm from the specified provider.NoSuchAlgorithmException - if the provider does not provide the requested algorithm.IllegalArgumentException - if provider == nullpublic final Provider getProvider()
KeyFactory.KeyFactory.public final String getAlgorithm()
KeyFactory.KeyFactory.public final PublicKey generatePublic(KeySpec keySpec) throws InvalidKeySpecException
PublicKey from the given key
specification.keySpec - the specification of the public keyInvalidKeySpecException - if the specified keySpec is invalidpublic final PrivateKey generatePrivate(KeySpec keySpec) throws InvalidKeySpecException
PrivateKey from the given key
specification.keySpec - the specification of the private key.InvalidKeySpecException - if the specified keySpec is invalid.public final <T extends KeySpec> T getKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException
key - the key from which the specification is requested.keySpec - the type of the requested KeySpec.InvalidKeySpecException - if the key can not be processed, or the requested requested
KeySpec is inappropriate for the given key.public final Key translateKey(Key key) throws InvalidKeyException
key - the key to translate.InvalidKeyException - if the specified key can not be translated by this key
factory.