public class KeyFactory extends Object
Key
) into key
specifications (transparent representations of the underlying key material), and vice versa.
Key factories are bi-directional. That is, they allow you to build an opaque key object from a given key specification (key material), or to retrieve the underlying key material of a key object in a suitable format.
Multiple compatible key specifications may exist for the same key. A key factory can be used to translate between compatible key specifications.
Key
,
PublicKey
,
PrivateKey
,
KeySpec
Constructor and Description |
---|
KeyFactory() |
Modifier and Type | Method and Description |
---|---|
PrivateKey |
generatePrivate(KeySpec keySpec)
Generates a private key object from the provided key specification (key material).
|
PublicKey |
generatePublic(KeySpec keySpec)
Generates a public key object from the provided key specification (key material).
|
String |
getAlgorithm()
Gets the name of the algorithm associated with this
KeyFactory . |
static KeyFactory |
getInstance(String algorithm)
Returns a KeyFactory object that converts public/private keys of the specified algorithm.
|
public final PrivateKey generatePrivate(KeySpec keySpec) throws InvalidKeySpecException
keySpec
- the specification (key material) of the private key.InvalidKeySpecException
- if the given key specification is inappropriate for this key factory to produce a private key.public final PublicKey generatePublic(KeySpec keySpec) throws InvalidKeySpecException
keySpec
- the specification (key material) of the public key.InvalidKeySpecException
- if the given key specification is inappropriate for this key factory to produce a public key.public final String getAlgorithm()
KeyFactory
.KeyFactory
public static KeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException
algorithm
- the name of the requested key algorithm. See the KeyFactory section in the
Java Cryptography
Architecture Standard Algorithm Name Documentation for information about standard algorithm names.NoSuchAlgorithmException
- if the KeyFactorySpi has no implementation for the specified algorithm.