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/TrustManagerFactory#proctors) \| [Methods](https://developer.android.com/reference/javax/net/ssl/TrustManagerFactory#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/javax/net/ssl/TrustManagerFactory#inhmethods)

# TrustManagerFactory


`
public


class
TrustManagerFactory
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

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

<br />

*** ** * ** ***

This class acts as a factory for trust managers based on a
source of trust material. Each trust manager manages a specific
type of trust material for use by secure sockets. The trust
material is based on a KeyStore and/or provider specific sources.

Android provides the following `TrustManagerFactory` algorithms:

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

<br />

**See also:**

- `https://developer.android.com/reference/javax/net/ssl/TrustManager`

## Summary

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

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

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` 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 https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` 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` | ` 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` | ` 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

### TrustManagerFactory

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

```
protected TrustManagerFactory (TrustManagerFactorySpi factorySpi, 
                Provider provider, 
                String algorithm)
```

Creates a TrustManagerFactory object.

<br />

| Parameters ||
|---|---|
| `factorySpi` | `TrustManagerFactorySpi`: 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 `TrustManagerFactory`
object.

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the algorithm name of this `TrustManagerFactory` 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 TrustManagerFactory algorithm name.

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

<br />

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

**See also:**

- `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 TrustManagerFactory getInstance (String algorithm)
```

Returns a `TrustManagerFactory` object that acts as a
factory for trust managers.

This method traverses the list of registered security Providers,
starting with the most preferred Provider.
A new TrustManagerFactory object encapsulating the
TrustManagerFactorySpi 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://developer.android.com/reference/java/security/Security#getProviders()` method.

<br />

| Parameters ||
|---|---|
| `algorithm` | `String`: the standard name of the requested trust management 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 ||
|---|---|
| `https://developer.android.com/reference/javax/net/ssl/TrustManagerFactory` | the new `TrustManagerFactory` object. <br /> |

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

**See also:**

- `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 TrustManagerFactory getInstance (String algorithm, 
                String provider)
```

Returns a `TrustManagerFactory` object that acts as a
factory for trust 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://developer.android.com/reference/java/security/Security#getProviders()` method.

<br />

| Parameters ||
|---|---|
| `algorithm` | `String`: the standard name of the requested trust management 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 ||
|---|---|
| `https://developer.android.com/reference/javax/net/ssl/TrustManagerFactory` | the new `TrustManagerFactory` object <br /> |

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

**See also:**

- `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 TrustManagerFactory getInstance (String algorithm, 
                Provider provider)
```

Returns a `TrustManagerFactory` object that acts as a
factory for trust managers.

A new TrustManagerFactory object encapsulating the
TrustManagerFactorySpi 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 trust management 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 ||
|---|---|
| `https://developer.android.com/reference/javax/net/ssl/TrustManagerFactory` | the new `TrustManagerFactory` object. <br /> |

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

**See also:**

- `https://developer.android.com/reference/java/security/Provider`

### 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 `TrustManagerFactory` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/Provider` | the provider of this `TrustManagerFactory` object <br /> |

### getTrustManagers

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

```
public final TrustManager[] getTrustManagers ()
```

Returns one trust manager for each type of trust material.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/javax/net/ssl/TrustManager` | the trust managers <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the factory is not initialized. |

### 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
trust material.


In some cases, initialization parameters other than a keystore
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 ||
|---|---|
| `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)
```

Initializes this factory with a source of certificate
authorities and related trust material.


The provider typically uses a KeyStore as a basis for making
trust decisions.


For more flexible initialization, please see
`https://developer.android.com/reference/javax/net/ssl/TrustManagerFactory#init(javax.net.ssl.ManagerFactoryParameters)`.

<br />

| Parameters ||
|---|---|
| `ks` | `KeyStore`: the key store, or null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/security/KeyStoreException` | if this operation fails |