Package java.security
Class KeyFactory
- java.lang.Object
-
- java.security.KeyFactory
-
public class KeyFactory extends java.lang.ObjectKey factories are used to convert keys (opaque cryptographic keys of typeKey) 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.
- Since:
- 1.2
- See Also:
Key,PublicKey,PrivateKey,KeySpec
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PrivateKeygeneratePrivate(KeySpec keySpec)Generates a private key object from the provided key specification (key material).PublicKeygeneratePublic(KeySpec keySpec)Generates a public key object from the provided key specification (key material).java.lang.StringgetAlgorithm()Gets the name of the algorithm associated with thisKeyFactory.static KeyFactorygetInstance(java.lang.String algorithm)Returns a KeyFactory object that converts public/private keys of the specified algorithm.
-
-
-
Method Detail
-
getInstance
public static KeyFactory getInstance(java.lang.String algorithm) throws NoSuchAlgorithmException
Returns a KeyFactory object that converts public/private keys of the specified algorithm.- Parameters:
algorithm- the name of the requested key algorithm. See the KeyFactory section in the Java Security Standard Algorithm Names Specification for information about standard algorithm names. Consult the release documentation for your implementation to see which algorithms are supported.- Returns:
- the new KeyFactory object.
- Throws:
NoSuchAlgorithmException- if the KeyFactorySpi has no implementation for the specified algorithm.
-
getAlgorithm
public final java.lang.String getAlgorithm()
Gets the name of the algorithm associated with thisKeyFactory.- Returns:
- the name of the algorithm associated with this
KeyFactory
-
generatePrivate
public final PrivateKey generatePrivate(KeySpec keySpec) throws InvalidKeySpecException
Generates a private key object from the provided key specification (key material).- Parameters:
keySpec- the specification (key material) of the private key.- Returns:
- the private key.
- Throws:
InvalidKeySpecException- if the given key specification is inappropriate for this key factory to produce a private key.
-
generatePublic
public final PublicKey generatePublic(KeySpec keySpec) throws InvalidKeySpecException
Generates a public key object from the provided key specification (key material).- Parameters:
keySpec- the specification (key material) of the public key.- Returns:
- the public key.
- Throws:
InvalidKeySpecException- if the given key specification is inappropriate for this key factory to produce a public key.
-
-