# KeyManagerFactory

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Protected Ctors](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactory#proctors)\|[Methods](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactory#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactory#inhmethods)  

# KeyManagerFactory

`
public


class
KeyManagerFactory
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|---------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | javax.net.ssl.KeyManagerFactory |

<br />

*** ** * ** ***

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:**

- [KeyManager](https://developer.android.com/reference/javax/net/ssl/KeyManager)

## Summary

|                                                                                                                                                                                                                                                      ### Protected constructors                                                                                                                                                                                                                                                       ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[KeyManagerFactory](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactory#KeyManagerFactory(javax.net.ssl.KeyManagerFactorySpi,%20java.security.Provider,%20java.lang.String))`(`[KeyManagerFactorySpi](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactorySpi)` factorySpi, `[Provider](https://developer.android.com/reference/java/security/Provider)` provider, `[String](https://developer.android.com/reference/java/lang/String)` algorithm) ` Creates a KeyManagerFactory object. |

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

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Protected constructors

### KeyManagerFactory

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected KeyManagerFactory (KeyManagerFactorySpi factorySpi, 
                Provider provider, 
                String algorithm)
```

Creates a KeyManagerFactory object.

<br />

|                        Parameters                         ||
|--------------|---------------------------------------------|
| `factorySpi` | `KeyManagerFactorySpi`: the delegate <br /> |
| `provider`   | `Provider`: the provider <br />             |
| `algorithm`  | `String`: the algorithm <br />              |

## Public methods

### getAlgorithm

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final String 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.

<br />

|                                                             Returns                                                             ||
|--------------------------------------------------------------------|-------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the algorithm name of this`KeyManagerFactory`object. <br /> |

### getDefaultAlgorithm

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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.algorithm`security property to the desired algorithm name.

<br />

|                                                                                                                    Returns                                                                                                                     ||
|--------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the default algorithm name as specified by the`ssl.KeyManagerFactory.algorithm`security property, or an implementation-specific default if no such property exists. <br /> |

**See also:**

- [security properties](https://developer.android.com/reference/java/security/Security)  

### getInstance

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final KeyManagerFactory getInstance (String 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[Security.getProviders()](https://developer.android.com/reference/java/security/Security#getProviders())method.

<br />

|                                                                                                                                Parameters                                                                                                                                ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `algorithm` | `String`: the standard name of the requested algorithm. See the[Java Secure Socket Extension Reference Guide](https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html)for information about standard algorithm names. <br /> |

|                                                                Returns                                                                 ||
|----------------------------------------------------------------------------------------------|------------------------------------------|
| [KeyManagerFactory](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactory) | the new`KeyManagerFactory`object. <br /> |

|                                                                                                 Throws                                                                                                 ||
|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| [NoSuchAlgorithmException](https://developer.android.com/reference/java/security/NoSuchAlgorithmException) | if no Provider supports a KeyManagerFactorySpi implementation for the specified algorithm. |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)             | if`algorithm`is null.                                                                      |

**See also:**

- [Provider](https://developer.android.com/reference/java/security/Provider)  

### getInstance

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final KeyManagerFactory getInstance (String algorithm, 
                String 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[Security.getProviders()](https://developer.android.com/reference/java/security/Security#getProviders())method.

<br />

|                                                                                                                                Parameters                                                                                                                                ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `algorithm` | `String`: the standard name of the requested algorithm. See the[Java Secure Socket Extension Reference Guide](https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html)for information about standard algorithm names. <br /> |
| `provider`  | `String`: the name of the provider. <br />                                                                                                                                                                                                                  |

|                                                                Returns                                                                 ||
|----------------------------------------------------------------------------------------------|------------------------------------------|
| [KeyManagerFactory](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactory) | the new`KeyManagerFactory`object. <br /> |

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

**See also:**

- [Provider](https://developer.android.com/reference/java/security/Provider)  

### getInstance

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final KeyManagerFactory getInstance (String algorithm, 
                Provider 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.

<br />

|                                                                                                                                Parameters                                                                                                                                ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `algorithm` | `String`: the standard name of the requested algorithm. See the[Java Secure Socket Extension Reference Guide](https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html)for information about standard algorithm names. <br /> |
| `provider`  | `Provider`: an instance of the provider. <br />                                                                                                                                                                                                             |

|                                                                Returns                                                                 ||
|----------------------------------------------------------------------------------------------|------------------------------------------|
| [KeyManagerFactory](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactory) | the new`KeyManagerFactory`object. <br /> |

|                                                                                                                Throws                                                                                                                 ||
|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| [NoSuchAlgorithmException](https://developer.android.com/reference/java/security/NoSuchAlgorithmException) | if a KeyManagerFactorySpi implementation for the specified algorithm is not available from the specified Provider object. |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException)     | if provider is null.                                                                                                      |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)             | if`algorithm`is null.                                                                                                     |

**See also:**

- [Provider](https://developer.android.com/reference/java/security/Provider)  

### getKeyManagers

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final KeyManager[] getKeyManagers ()
```

Returns one key manager for each type of key material.

<br />

|                                                  Returns                                                  ||
|----------------------------------------------------------------------------------|-------------------------|
| [KeyManager[]](https://developer.android.com/reference/javax/net/ssl/KeyManager) | the key managers <br /> |

|                                                                    Throws                                                                     ||
|--------------------------------------------------------------------------------------------------|---------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the KeyManagerFactory is not initialized |

### getProvider

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final Provider getProvider ()
```

Returns the provider of this`KeyManagerFactory`object.

<br />

|                                                             Returns                                                              ||
|----------------------------------------------------------------------------|------------------------------------------------------|
| [Provider](https://developer.android.com/reference/java/security/Provider) | the provider of this`KeyManagerFactory`object <br /> |

### init

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void init (ManagerFactoryParameters 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.

<br />

|                                                 Parameters                                                  ||
|--------|-----------------------------------------------------------------------------------------------------|
| `spec` | `ManagerFactoryParameters`: an implementation of a provider-specific parameter specification <br /> |

|                                                                           Throws                                                                           ||
|--------------------------------------------------------------------------------------------------------------------------------|----------------------------|
| [InvalidAlgorithmParameterException](https://developer.android.com/reference/java/security/InvalidAlgorithmParameterException) | if an error is encountered |

### init

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void init (KeyStore 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[init(javax.net.ssl.ManagerFactoryParameters)](https://developer.android.com/reference/javax/net/ssl/KeyManagerFactory#init(javax.net.ssl.ManagerFactoryParameters)).

<br />

<br />

|                                 Parameters                                  ||
|------------|-----------------------------------------------------------------|
| `ks`       | `KeyStore`: the key store or null <br />                        |
| `password` | `char`: the password for recovering keys in the KeyStore <br /> |

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