# KeyStore

public class **KeyStore** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
This class represents a storage facility for cryptographic
keys and certificates.

A `KeyStore` manages different types of entries.
Each type of entry implements the `KeyStore.Entry` interface.
Three basic `KeyStore.Entry` implementations are provided:

- **KeyStore.PrivateKeyEntry**

  This type of entry holds a cryptographic `PrivateKey`,
  which is optionally stored in a protected format to prevent
  unauthorized access. It is also accompanied by a certificate chain
  for the corresponding public key.

  Private keys and certificate chains are used by a given entity for
  self-authentication. Applications for this authentication include software
  distribution organizations which sign JAR files as part of releasing
  and/or licensing software.

- **KeyStore.SecretKeyEntry**

  This type of entry holds a cryptographic `SecretKey`,
  which is optionally stored in a protected format to prevent
  unauthorized access.

- **KeyStore.TrustedCertificateEntry**

  This type of entry contains a single public key `Certificate`
  belonging to another party. It is called a *trusted certificate*
  because the keystore owner trusts that the public key in the certificate
  indeed belongs to the identity identified by the *subject* (owner)
  of the certificate.

  This type of entry can be used to authenticate other parties.

Each entry in a keystore is identified by an "alias" string. In the
case of private keys and their associated certificate chains, these strings
distinguish among the different ways in which the entity may authenticate
itself. For example, the entity may authenticate itself using different
certificate authorities, or using different public key algorithms.

Whether aliases are case sensitive is implementation dependent. In order
to avoid problems, it is recommended not to use aliases in a KeyStore that
only differ in case.

Whether keystores are persistent, and the mechanisms used by the
keystore if it is persistent, are not specified here. This allows
use of a variety of techniques for protecting sensitive (e.g., private or
secret) keys. Smart cards or other integrated cryptographic engines
(SafeKeyper) are one option, and simpler mechanisms such as files may also
be used (in a variety of formats).

Typical ways to request a KeyStore object include
relying on the default type and providing a specific keystore type.

- To rely on the default type:

  ```
      KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
   
  ```
  The system will return a keystore implementation for the default type.
- To provide a specific keystore type:

  ```
        KeyStore ks = KeyStore.getInstance("JKS");
   
  ```
  The system will return the most preferred implementation of the specified keystore type available in the environment.


Before a keystore can be accessed, it must be
`https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#load(java.io.InputStream,%20char[])`.

```
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

    // get user password and file input stream
    char[] password = getPassword();

    try (FileInputStream fis = new FileInputStream("keyStoreName")) {
        ks.load(fis, password);
    }
 
```
To create an empty keystore using the above `load` method, pass `null` as the `InputStream` argument.

Once the keystore has been loaded, it is possible
to read existing entries from the keystore, or to write new entries
into the keystore:

```
    KeyStore.ProtectionParameter protParam =
        new KeyStore.PasswordProtection(password);

    // get my private key
    KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
        ks.getEntry("privateKeyAlias", protParam);
    PrivateKey myPrivateKey = pkEntry.getPrivateKey();

    // save my secret key
    javax.crypto.SecretKey mySecretKey;
    KeyStore.SecretKeyEntry skEntry =
        new KeyStore.SecretKeyEntry(mySecretKey);
    ks.setEntry("secretKeyAlias", skEntry, protParam);

    // store away the keystore
    try (FileOutputStream fos = new FileOutputStream("newKeyStoreName")) {
        ks.store(fos, password);
    }
 
```
Note that although the same password may be used to load the keystore, to protect the private key entry, to protect the secret key entry, and to store the keystore (as is shown in the sample code above), different passwords or other protection parameters may also be used.

Android provides the following `KeyStore` types:

| Algorithm | Supported API Levels |
|---|---|
| AndroidCAStore | 14+ |
| AndroidKeyStore | 18+ |
| BCPKCS12 | 1-8 |
| BKS | 1+ |
| BouncyCastle | 1+ |
| PKCS12 | 1+ |
| PKCS12-DEF | 1-8 |

These types are described in the [KeyStore section](https://developers.google.com/j2objc/javadoc/jre/technotes/guides/security/StandardNames.html#KeyStore) of the Java Cryptography Architecture Standard Algorithm Name Documentation.

<br />

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/PrivateKey.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/SecretKey.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html`

### Nested Class Summary

|---|---|---|---|
| class | [KeyStore.Builder](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Builder.html) || A description of a to-be-instantiated KeyStore object. |
| class | [KeyStore.CallbackHandlerProtection](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.CallbackHandlerProtection.html) || A ProtectionParameter encapsulating a CallbackHandler. |
| interface | [KeyStore.Entry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html) || A marker interface for `KeyStore` entry types. |
| interface | [KeyStore.LoadStoreParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.LoadStoreParameter.html) || A marker interface for `KeyStore` `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#load(java.security.KeyStore.LoadStoreParameter)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#store(java.security.KeyStore.LoadStoreParameter)` parameters. |
| class | [KeyStore.PasswordProtection](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.PasswordProtection.html) || A password-based implementation of `ProtectionParameter`. |
| class | [KeyStore.PrivateKeyEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.PrivateKeyEntry.html) || A `KeyStore` entry that holds a `PrivateKey` and corresponding certificate chain. |
| interface | [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) || A marker interface for keystore protection parameters. |
| class | [KeyStore.SecretKeyEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.SecretKeyEntry.html) || A `KeyStore` entry that holds a `SecretKey`. |
| class | [KeyStore.TrustedCertificateEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.TrustedCertificateEntry.html) || A `KeyStore` entry that holds a trusted `Certificate`. |

### Protected Constructor Summary

|---|---|
|   | [KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#KeyStore(java.security.KeyStoreSpi,%20java.security.Provider,%20java.lang.String))([KeyStoreSpi](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreSpi.html) keyStoreSpi, [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) type) Creates a KeyStore object of the given type, and encapsulates the given provider implementation (SPI object) in it. |

### Public Method Summary

|---|---|
| final [Enumeration](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Enumeration.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\> | [aliases](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#aliases())() Lists all the alias names of this keystore. |
| final boolean | [containsAlias](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#containsAlias(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias) Checks if the given alias exists in this keystore. |
| final void | [deleteEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#deleteEntry(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias) Deletes the entry identified by the given alias from this keystore. |
| final boolean | [entryInstanceOf](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#entryInstanceOf(java.lang.String,%20java.lang.Class<?%20extends%20java.security.KeyStore.Entry>))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<? extends [KeyStore.Entry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html)\> entryClass) Determines if the keystore `Entry` for the specified `alias` is an instance or subclass of the specified `entryClass`. |
| final [Certificate](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) | [getCertificate](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getCertificate(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias) Returns the certificate associated with the given alias. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getCertificateAlias](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getCertificateAlias(java.security.cert.Certificate))([Certificate](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) cert) Returns the (alias) name of the first keystore entry whose certificate matches the given certificate. |
| final [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) | [getCertificateChain](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getCertificateChain(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias) Returns the certificate chain associated with the given alias. |
| final [Date](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Date.html) | [getCreationDate](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getCreationDate(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias) Returns the creation date of the entry identified by the given alias. |
| final static [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getDefaultType](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getDefaultType())() Returns the default keystore type as specified by the `keystore.type` security property, or the string "jks" (acronym for "Java keystore") if no such property exists. |
| final [KeyStore.Entry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html) | [getEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getEntry(java.lang.String,%20java.security.KeyStore.ProtectionParameter))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protParam) Gets a keystore `Entry` for the specified alias with the specified protection parameter. |
| static [KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getInstance(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) type) Returns a keystore object of the specified type. |
| static [KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getInstance(java.lang.String,%20java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) type, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) provider) Returns a keystore object of the specified type. |
| static [KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html) | [getInstance](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getInstance(java.lang.String,%20java.security.Provider))([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) Returns a keystore object of the specified type. |
| final [Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) | [getKey](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getKey(java.lang.String,%20char[]))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, char\[\] password) Returns the key associated with the given alias, using the given password to recover it. |
| final [Provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Provider.html) | [getProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getProvider())() Returns the provider of this keystore. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getType](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getType())() Returns the type of this keystore. |
| final boolean | [isCertificateEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#isCertificateEntry(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias) Returns true if the entry identified by the given alias was created by a call to `setCertificateEntry`, or created by a call to `setEntry` with a `TrustedCertificateEntry`. |
| final boolean | [isKeyEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#isKeyEntry(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias) Returns true if the entry identified by the given alias was created by a call to `setKeyEntry`, or created by a call to `setEntry` with a `PrivateKeyEntry` or a `SecretKeyEntry`. |
| final void | [load](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#load(java.security.KeyStore.LoadStoreParameter))([KeyStore.LoadStoreParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.LoadStoreParameter.html) param) Loads this keystore using the given `LoadStoreParameter`. |
| final void | [load](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#load(java.io.InputStream,%20char[]))([InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html) stream, char\[\] password) Loads this KeyStore from the given input stream. |
| final void | [setCertificateEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#setCertificateEntry(java.lang.String,%20java.security.cert.Certificate))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [Certificate](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) cert) Assigns the given trusted certificate to the given alias. |
| final void | [setEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#setEntry(java.lang.String,%20java.security.KeyStore.Entry,%20java.security.KeyStore.ProtectionParameter))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [KeyStore.Entry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html) entry, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protParam) Saves a keystore `Entry` under the specified alias. |
| final void | [setKeyEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#setKeyEntry(java.lang.String,%20java.security.Key,%20char[],%20java.security.cert.Certificate[]))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key, char\[\] password, [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) chain) Assigns the given key to the given alias, protecting it with the given password. |
| final void | [setKeyEntry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#setKeyEntry(java.lang.String,%20byte[],%20java.security.cert.Certificate[]))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, byte\[\] key, [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) chain) Assigns the given key (that has already been protected) to the given alias. |
| final int | [size](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#size())() Retrieves the number of entries in this keystore. |
| final void | [store](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#store(java.io.OutputStream,%20char[]))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) stream, char\[\] password) Stores this keystore to the given output stream, and protects its integrity with the given password. |
| final void | [store](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#store(java.security.KeyStore.LoadStoreParameter))([KeyStore.LoadStoreParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.LoadStoreParameter.html) param) Stores this keystore using the given `LoadStoreParameter`. |

### 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
**KeyStore**
([KeyStoreSpi](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreSpi.html) keyStoreSpi, [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) type)

Creates a KeyStore object of the given type, and encapsulates the given
provider implementation (SPI object) in it.

##### Parameters

| keyStoreSpi | the provider implementation. |
| provider | the provider. |
| type | the keystore type. |
|---|---|

## Public Methods

#### public final [Enumeration](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Enumeration.html)\<[String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)\>
**aliases**
()

Lists all the alias names of this keystore.

##### Returns

- enumeration of the alias names

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

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

Checks if the given alias exists in this keystore.

##### Parameters

| alias | the alias name |
|---|---|

##### Returns

- true if the alias exists, false otherwise

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

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

Deletes the entry identified by the given alias from this keystore.

##### Parameters

| alias | the alias name |
|---|---|

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized, or if the entry cannot be removed. |
|---|---|

#### public final boolean
**entryInstanceOf**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<? extends [KeyStore.Entry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html)\> entryClass)

Determines if the keystore `Entry` for the specified
`alias` is an instance or subclass of the specified
`entryClass`.

##### Parameters

| alias | the alias name |
| entryClass | the entry class |
|---|---|

##### Returns

- true if the keystore `Entry` for the specified `alias` is an instance or subclass of the specified `entryClass`, false otherwise

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `alias` or `entryClass` is `null` |
| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded) |
|---|---|

#### public final [Certificate](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html)
**getCertificate**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias)

Returns the certificate associated with the given alias.

If the given alias name identifies an entry
created by a call to `setCertificateEntry`,
or created by a call to `setEntry` with a
`TrustedCertificateEntry`,
then the trusted certificate contained in that entry is returned.

If the given alias name identifies an entry
created by a call to `setKeyEntry`,
or created by a call to `setEntry` with a
`PrivateKeyEntry`,
then the first element of the certificate chain in that entry
is returned.

##### Parameters

| alias | the alias name |
|---|---|

##### Returns

- the certificate, or null if the given alias does not exist or does not contain a certificate.

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

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

Returns the (alias) name of the first keystore entry whose certificate
matches the given certificate.

This method attempts to match the given certificate with each
keystore entry. If the entry being considered was
created by a call to `setCertificateEntry`,
or created by a call to `setEntry` with a
`TrustedCertificateEntry`,
then the given certificate is compared to that entry's certificate.

If the entry being considered was
created by a call to `setKeyEntry`,
or created by a call to `setEntry` with a
`PrivateKeyEntry`,
then the given certificate is compared to the first
element of that entry's certificate chain.

##### Parameters

| cert | the certificate to match with. |
|---|---|

##### Returns

- the alias name of the first entry with a matching certificate, or null if no such entry exists in this keystore.

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

#### public final [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html)
**getCertificateChain**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias)

Returns the certificate chain associated with the given alias.
The certificate chain must have been associated with the alias
by a call to `setKeyEntry`,
or by a call to `setEntry` with a
`PrivateKeyEntry`.

##### Parameters

| alias | the alias name |
|---|---|

##### Returns

- the certificate chain (ordered with the user's certificate first followed by zero or more certificate authorities), or null if the given alias does not exist or does not contain a certificate chain

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

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

Returns the creation date of the entry identified by the given alias.

##### Parameters

| alias | the alias name |
|---|---|

##### Returns

- the creation date of this entry, or null if the given alias does not exist

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

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

Returns the default keystore type as specified by the
`keystore.type` security property, or the string
"jks" (acronym for "Java keystore")
if no such property exists.

The default keystore type can be used by applications that do not
want to use a hard-coded keystore type when calling one of the
`getInstance` methods, and want to provide a default keystore
type in case a user does not specify its own.

The default keystore type can be changed by setting the value of the
`keystore.type` security property to the desired keystore type.

##### Returns

- the default keystore type as specified by the `keystore.type` security property, or the string "jks" if no such property exists.

##### See Also

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

#### public final [KeyStore.Entry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html)
**getEntry**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protParam)

Gets a keystore `Entry` for the specified alias
with the specified protection parameter.

##### Parameters

| alias | get the keystore `Entry` for this alias |
| protParam | the `ProtectionParameter` used to protect the `Entry`, which may be `null` |
|---|---|

##### Returns

- the keystore `Entry` for the specified alias, or `null` if there is no such entry

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `alias` is `null` |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if the algorithm for recovering the entry cannot be found |
| [UnrecoverableEntryException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/UnrecoverableEntryException.html) | if the specified `protParam` were insufficient or invalid |
| [UnrecoverableKeyException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/UnrecoverableKeyException.html) | if the entry is a `PrivateKeyEntry` or `SecretKeyEntry` and the specified `protParam` does not contain the information needed to recover the key (e.g. wrong password) |
| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#setEntry(java.lang.String,%20java.security.KeyStore.Entry,%20java.security.KeyStore.ProtectionParameter)`

#### public static [KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html)
**getInstance**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) type)

Returns a keystore object of the specified type.

This method traverses the list of registered security Providers,
starting with the most preferred Provider.
A new KeyStore object encapsulating the
KeyStoreSpi implementation from the first
Provider that supports the specified type 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

| type | the type of keystore. See the KeyStore section in the [Java Cryptography Architecture Standard Algorithm Name Documentation](https://developers.google.com/j2objc/javadoc/jre/technotes/guides/security/StandardNames.html#KeyStore) for information about standard keystore types. |
|---|---|

##### Returns

- a keystore object of the specified type.

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if no Provider supports a KeyStoreSpi implementation for the specified type. |
|---|---|

##### See Also

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

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

Returns a keystore object of the specified type.

A new KeyStore object encapsulating the
KeyStoreSpi 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

| type | the type of keystore. See the KeyStore section in the [Java Cryptography Architecture Standard Algorithm Name Documentation](https://developers.google.com/j2objc/javadoc/jre/technotes/guides/security/StandardNames.html#KeyStore) for information about standard keystore types. |
| provider | the name of the provider. |
|---|---|

##### Returns

- a keystore object of the specified type.

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if a KeyStoreSpi implementation for the specified type 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. |
|---|---|

##### See Also

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

#### public static [KeyStore](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html)
**getInstance**
([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)

Returns a keystore object of the specified type.

A new KeyStore object encapsulating the
KeyStoreSpi 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

| type | the type of keystore. See the KeyStore section in the [Java Cryptography Architecture Standard Algorithm Name Documentation](https://developers.google.com/j2objc/javadoc/jre/technotes/guides/security/StandardNames.html#KeyStore) for information about standard keystore types. |
| provider | the provider. |
|---|---|

##### Returns

- a keystore object of the specified type.

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if KeyStoreSpi implementation for the specified type is not available from the specified Provider object. |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the specified provider is null. |
|---|---|

##### See Also

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

#### public final [Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html)
**getKey**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, char\[\] password)

Returns the key associated with the given alias, using the given
password to recover it. The key must have been associated with
the alias by a call to `setKeyEntry`,
or by a call to `setEntry` with a
`PrivateKeyEntry` or `SecretKeyEntry`.

##### Parameters

| alias | the alias name |
| password | the password for recovering the key |
|---|---|

##### Returns

- the requested key, or null if the given alias does not exist or does not identify a key-related entry.

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if the algorithm for recovering the key cannot be found |
| [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). |
|---|---|

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

Returns the provider of this keystore.

##### Returns

- the provider of this keystore.

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

Returns the type of this keystore.

##### Returns

- the type of this keystore.

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

Returns true if the entry identified by the given alias
was created by a call to `setCertificateEntry`,
or created by a call to `setEntry` with a
`TrustedCertificateEntry`.

##### Parameters

| alias | the alias for the keystore entry to be checked |
|---|---|

##### Returns

- true if the entry identified by the given alias contains a trusted certificate, false otherwise.

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

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

Returns true if the entry identified by the given alias
was created by a call to `setKeyEntry`,
or created by a call to `setEntry` with a
`PrivateKeyEntry` or a `SecretKeyEntry`.

##### Parameters

| alias | the alias for the keystore entry to be checked |
|---|---|

##### Returns

- true if the entry identified by the given alias is a key-related entry, false otherwise.

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

#### public final void
**load**
([KeyStore.LoadStoreParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.LoadStoreParameter.html) param)

Loads this keystore using the given `LoadStoreParameter`.

Note that if this KeyStore has already been loaded, it is
reinitialized and loaded again from the given parameter.

##### Parameters

| param | the `LoadStoreParameter` that specifies how to load the keystore, which may be `null` |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the given `LoadStoreParameter` input is not recognized |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if there is an I/O or format problem with the keystore data. If the error is due to an incorrect `ProtectionParameter` (e.g. wrong password) the `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getCause()` of the `IOException` should be an `UnrecoverableKeyException` |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if the algorithm used to check the integrity of the keystore cannot be found |
| [CertificateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/CertificateException.html) | if any of the certificates in the keystore could not be loaded |
|---|---|

#### public final void
**load**
([InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html) stream, char\[\] password)

Loads this KeyStore from the given input stream.

A password may be given to unlock the keystore
(e.g. the keystore resides on a hardware token device),
or to check the integrity of the keystore data.
If a password is not given for integrity checking,
then integrity checking is not performed.

In order to create an empty keystore, or if the keystore cannot
be initialized from a stream, pass `null`
as the `stream` argument.

Note that if this keystore has already been loaded, it is
reinitialized and loaded again from the given input stream.

##### Parameters

| stream | the input stream from which the keystore is loaded, or `null` |
| password | the password used to check the integrity of the keystore, the password used to unlock the keystore, or `null` |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getCause()` of the `IOException` should be an `UnrecoverableKeyException` |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if the algorithm used to check the integrity of the keystore cannot be found |
| [CertificateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/CertificateException.html) | if any of the certificates in the keystore could not be loaded |
|---|---|

#### public final void
**setCertificateEntry**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [Certificate](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) cert)

Assigns the given trusted certificate to the given alias.

If the given alias identifies an existing entry
created by a call to `setCertificateEntry`,
or created by a call to `setEntry` with a
`TrustedCertificateEntry`,
the trusted certificate in the existing entry
is overridden by the given certificate.

##### Parameters

| alias | the alias name |
| cert | the certificate |
|---|---|

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized, or the given alias already exists and does not identify an entry containing a trusted certificate, or this operation fails for some other reason. |
|---|---|

#### public final void
**setEntry**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [KeyStore.Entry](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.Entry.html) entry, [KeyStore.ProtectionParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.ProtectionParameter.html) protParam)

Saves a keystore `Entry` under the specified alias.
The protection parameter is used to protect the
`Entry`.

If an entry already exists for the specified alias,
it is overridden.

##### Parameters

| alias | save the keystore `Entry` under this alias |
| entry | the `Entry` to save |
| protParam | the `ProtectionParameter` used to protect the `Entry`, which may be `null` |
|---|---|

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `alias` or `entry` is `null` |
| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded), or if this operation fails for some other reason |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.html#getEntry(java.lang.String,%20java.security.KeyStore.ProtectionParameter)`

#### public final void
**setKeyEntry**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, [Key](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html) key, char\[\] password, [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) chain)

Assigns the given key to the given alias, protecting it with the given
password.

If the given key is of type `java.security.PrivateKey`,
it must be accompanied by a certificate chain certifying the
corresponding public key.

If the given alias already exists, the keystore information
associated with it is overridden by the given key (and possibly
certificate chain).

##### Parameters

| alias | the alias name |
| key | the key to be associated with the alias |
| password | the password to protect the key |
| chain | the certificate chain for the corresponding public key (only required if the given key is of type `java.security.PrivateKey`). |
|---|---|

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded), the given key cannot be protected, or this operation fails for some other reason |
|---|---|

#### public final void
**setKeyEntry**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) alias, byte\[\] key, [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) chain)

Assigns the given key (that has already been protected) to the given
alias.

If the protected key is of type
`java.security.PrivateKey`, it must be accompanied by a
certificate chain certifying the corresponding public key. If the
underlying keystore implementation is of type `jks`,
`key` must be encoded as an
`EncryptedPrivateKeyInfo` as defined in the PKCS #8 standard.

If the given alias already exists, the keystore information
associated with it is overridden by the given key (and possibly
certificate chain).

##### Parameters

| alias | the alias name |
| key | the key (in protected format) to be associated with the alias |
| chain | the certificate chain for the corresponding public key (only useful if the protected key is of type `java.security.PrivateKey`). |
|---|---|

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded), or if this operation fails for some other reason. |
|---|---|

#### public final int
**size**
()

Retrieves the number of entries in this keystore.

##### Returns

- the number of entries in this keystore

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
|---|---|

#### public final void
**store**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) stream, char\[\] password)

Stores this keystore to the given output stream, and protects its
integrity with the given password.

##### Parameters

| stream | the output stream to which this keystore is written. |
| password | the password to generate the keystore integrity check |
|---|---|

##### Throws

| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded). |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if there was an I/O problem with data |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if the appropriate data integrity algorithm could not be found |
| [CertificateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/CertificateException.html) | if any of the certificates included in the keystore data could not be stored |
|---|---|

#### public final void
**store**
([KeyStore.LoadStoreParameter](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStore.LoadStoreParameter.html) param)

Stores this keystore using the given `LoadStoreParameter`.

##### Parameters

| param | the `LoadStoreParameter` that specifies how to store the keystore, which may be `null` |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the given `LoadStoreParameter` input is not recognized |
| [KeyStoreException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyStoreException.html) | if the keystore has not been initialized (loaded) |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if there was an I/O problem with data |
| [NoSuchAlgorithmException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/NoSuchAlgorithmException.html) | if the appropriate data integrity algorithm could not be found |
| [CertificateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/CertificateException.html) | if any of the certificates included in the keystore data could not be stored |
|---|---|