Package javax.net.ssl
Class KeyManagerFactory
- java.lang.Object
-
- javax.net.ssl.KeyManagerFactory
-
public class KeyManagerFactory extends Object
This class acts as a factory for key managers based on a source of key material. Each key manager manages a specific type of key material for use by secure sockets. The key material is based on a KeyStore and/or provider specific sources.- Since:
- 1.4
- See Also:
KeyManager
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetAlgorithm()Returns the algorithm name of thisKeyManagerFactoryobject.static StringgetDefaultAlgorithm()Obtains the default KeyManagerFactory algorithm name.static KeyManagerFactorygetInstance(String algorithm)Returns aKeyManagerFactoryobject that acts as a factory for key managers.KeyManager[]getKeyManagers()Returns one key manager for each type of key material.voidinit(KeyStore ks, char[] password)Initializes this factory with a source of key material.
-
-
-
Method Detail
-
getDefaultAlgorithm
public static final String getDefaultAlgorithm()
Obtains the default KeyManagerFactory algorithm name.The default algorithm can be changed at runtime by setting the value of the
ssl.KeyManagerFactory.algorithmsecurity property to the desired algorithm name.- Returns:
- the default algorithm name as specified by the
ssl.KeyManagerFactory.algorithmsecurity property, or an implementation-specific default if no such property exists.
-
getAlgorithm
public final String getAlgorithm()
Returns the algorithm name of thisKeyManagerFactoryobject.This is the same name that was specified in one of the
getInstancecalls that created thisKeyManagerFactoryobject.- Returns:
- the algorithm name of this
KeyManagerFactoryobject.
-
getInstance
public static final KeyManagerFactory getInstance(String algorithm) throws NoSuchAlgorithmException
Returns aKeyManagerFactoryobject that acts as a factory for key managers.This method traverses the list of registered security Providers, starting with the most preferred Provider. A new KeyManagerFactory object encapsulating the KeyManagerFactorySpi implementation from the first Provider that supports the specified algorithm is returned.
- Parameters:
algorithm- the standard name of the requested algorithm. See the Java Secure Socket Extension Reference Guide for information about standard algorithm names.- Returns:
- the new
KeyManagerFactoryobject. - Throws:
NoSuchAlgorithmException- if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm.NullPointerException- ifalgorithmis null.
-
init
public final void init(@Nullable KeyStore ks, char[] password) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException
Initializes this factory with a source of key material.The provider typically uses a KeyStore for obtaining key material for use during secure socket negotiations. The KeyStore is generally password-protected.
- Parameters:
ks- the key store or nullpassword- the password for recovering keys in the KeyStore- Throws:
KeyStoreException- if this operation failsNoSuchAlgorithmException- if the specified algorithm is not available from the specified provider.UnrecoverableKeyException- if the key cannot be recovered (e.g. the given password is wrong).
-
getKeyManagers
public final KeyManager[] getKeyManagers()
Returns one key manager for each type of key material.- Returns:
- the key managers
- Throws:
IllegalStateException- if the KeyManagerFactory is not initialized
-
-