# KeyManagerFactory

public class **KeyManagerFactory** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
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.

Android provides the following `KeyManagerFactory` algorithms:

| Algorithm | Supported API Levels |
|---|---|
| PKIX | 1+ |

<br />

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManager.html`

### Protected Constructor Summary

|---|---|
|   | [KeyManagerFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#KeyManagerFactory(javax.net.ssl.KeyManagerFactorySpi,%20java.security.Provider,%20java.lang.String))([KeyManagerFactorySpi](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactorySpi.html) factorySpi, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm) Creates a KeyManagerFactory object. |

### Public Method Summary

|---|---|
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getAlgorithm](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#getAlgorithm())() Returns the algorithm name of this `KeyManagerFactory` object. |
| final static [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getDefaultAlgorithm](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#getDefaultAlgorithm())() Obtains the default KeyManagerFactory algorithm name. |
| final static [KeyManagerFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#getInstance(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm) Returns a `KeyManagerFactory` object that acts as a factory for key managers. |
| final static [KeyManagerFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#getInstance(java.lang.String,%20java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) provider) Returns a `KeyManagerFactory` object that acts as a factory for key managers. |
| final static [KeyManagerFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#getInstance(java.lang.String,%20java.security.Provider))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider) Returns a `KeyManagerFactory` object that acts as a factory for key managers. |
| final [KeyManager\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManager.html) | [getKeyManagers](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#getKeyManagers())() Returns one key manager for each type of key material. |
| final [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) | [getProvider](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#getProvider())() Returns the provider of this `KeyManagerFactory` object. |
| final void | [init](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#init(javax.net.ssl.ManagerFactoryParameters))([ManagerFactoryParameters](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/ManagerFactoryParameters.html) spec) Initializes this factory with a source of provider-specific key material. |
| final void | [init](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#init(java.security.KeyStore,%20char[]))([KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html) ks, char\[\] password) Initializes this factory with a source of key material. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Protected Constructors

#### protected
**KeyManagerFactory**
([KeyManagerFactorySpi](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactorySpi.html) factorySpi, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm)

Creates a KeyManagerFactory object.

##### Parameters

| factorySpi | the delegate |
| provider | the provider |
| algorithm | the algorithm |
|---|---|

## Public Methods

#### public final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getAlgorithm**
()

Returns the algorithm name of this `KeyManagerFactory` object.

This is the same name that was specified in one of the
`getInstance` calls that created this
`KeyManagerFactory` object.

##### Returns

- the algorithm name of this `KeyManagerFactory` object.

#### public static final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getDefaultAlgorithm**
()

Obtains the default KeyManagerFactory algorithm name.

The default algorithm can be changed at runtime by setting
the value of the `ssl.KeyManagerFactory.algorithm`
security property to the desired algorithm name.

##### Returns

- the default algorithm name as specified by the `ssl.KeyManagerFactory.algorithm` security property, or an implementation-specific default if no such property exists.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Security.html`

#### public static final [KeyManagerFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html)
**getInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm)

Returns a `KeyManagerFactory` object 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.

Note that the list of registered providers may be retrieved via
the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Security.html#getProviders()` method.

##### Parameters

| algorithm | the standard name of the requested algorithm. See the [Java Secure Socket Extension Reference Guide](https://developers.google.com/j2objc/javadoc/jre/openjdk-redirect.html?v=8&path=/technotes/guides/security/jsse/JSSERefGuide.html) for information about standard algorithm names. |
|---|---|

##### Returns

- the new `KeyManagerFactory` object.

##### Throws

| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `algorithm` is null. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html`

#### public static final [KeyManagerFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html)
**getInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) provider)

Returns a `KeyManagerFactory` object that acts as a
factory for key managers.

A new KeyManagerFactory object encapsulating the
KeyManagerFactorySpi implementation from the specified provider
is returned. The specified provider must be registered
in the security provider list.

Note that the list of registered providers may be retrieved via
the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Security.html#getProviders()` method.

##### Parameters

| algorithm | the standard name of the requested algorithm. See the [Java Secure Socket Extension Reference Guide](https://developers.google.com/j2objc/javadoc/jre/openjdk-redirect.html?v=8&path=/technotes/guides/security/jsse/JSSERefGuide.html) for information about standard algorithm names. |
| provider | the name of the provider. |
|---|---|

##### Returns

- the new `KeyManagerFactory` object.

##### Throws

| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if a KeyManagerFactorySpi implementation for the specified algorithm is not available from the specified provider. |
| [NoSuchProviderException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchProviderException.html) | if the specified provider is not registered in the security provider list. |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the provider name is null or empty. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `algorithm` is null. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html`

#### public static final [KeyManagerFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html)
**getInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider)

Returns a `KeyManagerFactory` object that acts as a
factory for key managers.

A new KeyManagerFactory object encapsulating the
KeyManagerFactorySpi implementation from the specified Provider
object is returned. Note that the specified Provider object
does not have to be registered in the provider list.

##### Parameters

| algorithm | the standard name of the requested algorithm. See the [Java Secure Socket Extension Reference Guide](https://developers.google.com/j2objc/javadoc/jre/openjdk-redirect.html?v=8&path=/technotes/guides/security/jsse/JSSERefGuide.html) for information about standard algorithm names. |
| provider | an instance of the provider. |
|---|---|

##### Returns

- the new `KeyManagerFactory` object.

##### Throws

| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if a KeyManagerFactorySpi implementation for the specified algorithm is not available from the specified Provider object. |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if provider is null. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `algorithm` is null. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html`

#### public final [KeyManager\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManager.html)
**getKeyManagers**
()

Returns one key manager for each type of key material.

##### Returns

- the key managers

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | if the KeyManagerFactory is not initialized |
|---|---|

#### public final [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html)
**getProvider**
()

Returns the provider of this `KeyManagerFactory` object.

##### Returns

- the provider of this `KeyManagerFactory` object

#### public final void
**init**
([ManagerFactoryParameters](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/ManagerFactoryParameters.html) spec)

Initializes this factory with a source of provider-specific
key material.


In some cases, initialization parameters other than a keystore
and password may be needed by a provider. Users of that
particular provider are expected to pass an implementation of
the appropriate `ManagerFactoryParameters` as
defined by the provider. The provider can then call the
specified methods in the `ManagerFactoryParameters`
implementation to obtain the needed information.

##### Parameters

| spec | an implementation of a provider-specific parameter specification |
|---|---|

##### Throws

| [InvalidAlgorithmParameterException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/InvalidAlgorithmParameterException.html) | if an error is encountered |
|---|---|

#### public final void
**init**
([KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html) ks, char\[\] password)

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.


For more flexible initialization, please see
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyManagerFactory.html#init(javax.net.ssl.ManagerFactoryParameters)`.

<br />

##### Parameters

| ks | the key store or null |
| password | the password for recovering keys in the KeyStore |
|---|---|

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if this operation fails |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if the specified algorithm is not available from the specified provider. |
| [UnrecoverableKeyException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/UnrecoverableKeyException.html) | if the key cannot be recovered (e.g. the given password is wrong). |
|---|---|