# KeyStore.Builder

public static abstract class **KeyStore.Builder** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
A description of a to-be-instantiated KeyStore object.

An instance of this class encapsulates the information needed to
instantiate and initialize a KeyStore object. That process is
triggered when the {@linkplain #getKeyStore} method is called.

This makes it possible to decouple configuration from KeyStore
object creation and e.g. delay a password prompt until it is
needed.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/KeyStoreBuilderParameters.html`

### Protected Constructor Summary

|---|---|
|   | [Builder](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#Builder())() Construct a new Builder. |

### Public Method Summary

|---|---|
| abstract [KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html) | [getKeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getKeyStore())() Returns the KeyStore described by this object. |
| abstract [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) | [getProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getProtectionParameter(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias) Returns the ProtectionParameters that should be used to obtain the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html` with the given alias. |
| static [KeyStore.Builder](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html) | [newInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#newInstance(java.lang.String,%20java.security.Provider,%20java.security.KeyStore.ProtectionParameter))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) type, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protection) Returns a new Builder object. |
| static [KeyStore.Builder](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html) | [newInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#newInstance(java.lang.String,%20java.security.Provider,%20java.io.File,%20java.security.KeyStore.ProtectionParameter))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) type, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider, [File](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/File.html) file, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protection) Returns a new Builder object. |
| static [KeyStore.Builder](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html) | [newInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#newInstance(java.security.KeyStore,%20java.security.KeyStore.ProtectionParameter))([KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html) keyStore, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protectionParameter) Returns a new Builder that encapsulates the given KeyStore. |

### 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
**Builder**
()

Construct a new Builder.

## Public Methods

#### public abstract [KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html)
**getKeyStore**
()

Returns the KeyStore described by this object.

##### Returns

- the `KeyStore` described by this object

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if an error occurred during the operation, for example if the KeyStore could not be instantiated or loaded |
|---|---|

#### public abstract [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html)
**getProtectionParameter**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias)

Returns the ProtectionParameters that should be used to obtain
the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html` with the given alias.
The `getKeyStore` method must be invoked before this
method may be called.

##### Parameters

| alias | the alias of the KeyStore entry |
|---|---|

##### Returns

- the ProtectionParameters that should be used to obtain the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html` with the given alias.

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if alias is null |
| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if an error occurred during the operation |
| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | if the getKeyStore method has not been invoked prior to calling this method |
|---|---|

#### public static [KeyStore.Builder](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html)
**newInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) type, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protection)

Returns a new Builder object.

Each call to the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getKeyStore()` method on the returned
builder will return a new KeyStore object of type `type`.
Its `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#load(java.security.KeyStore.LoadStoreParameter)`
method is invoked using a
`LoadStoreParameter` that encapsulates
`protection`.

The KeyStore is instantiated from `provider` if
non-null. Otherwise, all installed providers are searched.

Calls to `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getProtectionParameter(java.lang.String)`
will return `protection`.

*Note* that the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getKeyStore()` method is executed
within the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AccessControlContext.html` of the code invoking this
method.

##### Parameters

| type | the type of KeyStore to be constructed |
| provider | the provider from which the KeyStore is to be instantiated (or null) |
| protection | the ProtectionParameter securing the Keystore |
|---|---|

##### Returns

- a new Builder object

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if type or protection is null |
|---|---|

#### public static [KeyStore.Builder](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html)
**newInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) type, [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) provider, [File](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/File.html) file, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protection)

Returns a new Builder object.

The first call to the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getKeyStore()` method on the returned
builder will create a KeyStore of type `type` and call
its `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#load(java.io.InputStream,%20char[])` method.
The `inputStream` argument is constructed from
`file`.
If `protection` is a
`PasswordProtection`, the password is obtained by
calling the `getPassword` method.
Otherwise, if `protection` is a
`CallbackHandlerProtection`, the password is obtained
by invoking the CallbackHandler.

Subsequent calls to `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getKeyStore()` return the same object
as the initial call. If the initial call to failed with a
KeyStoreException, subsequent calls also throw a
KeyStoreException.

The KeyStore is instantiated from `provider` if
non-null. Otherwise, all installed providers are searched.

Calls to `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getProtectionParameter(java.lang.String)`
will return a `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.PasswordProtection.html`
object encapsulating the password that was used to invoke the
`load` method.

*Note* that the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html#getKeyStore()` method is executed
within the `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/AccessControlContext.html` of the code invoking this
method.

##### Parameters

| type | the type of KeyStore to be constructed |
| provider | the provider from which the KeyStore is to be instantiated (or null) |
| file | the File that contains the KeyStore data |
| protection | the ProtectionParameter securing the KeyStore data |
|---|---|

##### Returns

- a new Builder object

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if type, file or protection is null |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if protection is not an instance of either PasswordProtection or CallbackHandlerProtection; or if file does not exist or does not refer to a normal file |
|---|---|

#### public static [KeyStore.Builder](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html)
**newInstance**
([KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html) keyStore, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protectionParameter)

Returns a new Builder that encapsulates the given KeyStore.
The {@linkplain #getKeyStore} method of the returned object
will return `keyStore`, the {@linkplain #getProtectionParameter getProtectionParameter()} method will
return `protectionParameters`.

This is useful if an existing KeyStore object needs to be
used with Builder-based APIs.

##### Parameters

| keyStore | the KeyStore to be encapsulated |
| protectionParameter | the ProtectionParameter used to protect the KeyStore entries |
|---|---|

##### Returns

- a new Builder object

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if keyStore or protectionParameters is null |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the keyStore has not been initialized |
|---|---|