Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#pubctors) \| [Methods](https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#inhmethods)

# KeyStore.PrivateKeyEntry


`
public
static
final

class
KeyStore.PrivateKeyEntry
`


`

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


`

`


implements

https://developer.android.com/reference/java/security/KeyStore.Entry


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.security.KeyStore.PrivateKeyEntry |

<br />

*** ** * ** ***

A `KeyStore` entry that holds a `PrivateKey`
and corresponding certificate chain.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#PrivateKeyEntry(java.security.PrivateKey,%20java.security.cert.Certificate[])(https://developer.android.com/reference/java/security/PrivateKey privateKey, https://developer.android.com/reference/java/security/cert/Certificate chain) ` Constructs a `PrivateKeyEntry` with a `PrivateKey` and corresponding certificate chain. |
| ` https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#PrivateKeyEntry(java.security.PrivateKey,%20java.security.cert.Certificate[],%20java.util.Set<java.security.KeyStore.Entry.Attribute>)(https://developer.android.com/reference/java/security/PrivateKey privateKey, https://developer.android.com/reference/java/security/cert/Certificate chain, https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/security/KeyStore.Entry.Attribute> attributes) ` Constructs a `PrivateKeyEntry` with a `PrivateKey` and corresponding certificate chain and associated entry attributes. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/security/KeyStore.Entry.Attribute>` | ` https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#getAttributes()() ` Retrieves the attributes associated with an entry. |
| ` https://developer.android.com/reference/java/security/cert/Certificate` | ` https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#getCertificate()() ` Gets the end entity `Certificate` from the certificate chain in this entry. |
| ` https://developer.android.com/reference/java/security/cert/Certificate` | ` https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#getCertificateChain()() ` Gets the `Certificate` chain from this entry. |
| ` https://developer.android.com/reference/java/security/PrivateKey` | ` https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#getPrivateKey()() ` Gets the `PrivateKey` from this entry. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/security/KeyStore.PrivateKeyEntry#toString()() ` Returns a string representation of this PrivateKeyEntry. |

| ### 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*. | ||
| From interface ` https://developer.android.com/reference/java/security/KeyStore.Entry ` |---|---| | ` default https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/security/KeyStore.Entry.Attribute>` | ` https://developer.android.com/reference/java/security/KeyStore.Entry#getAttributes()() ` Retrieves the attributes associated with an entry. | ||

## Public constructors

### PrivateKeyEntry

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

```
public PrivateKeyEntry (PrivateKey privateKey, 
                Certificate[] chain)
```

Constructs a `PrivateKeyEntry` with a
`PrivateKey` and corresponding certificate chain.

The specified `chain` is cloned before it is stored
in the new `PrivateKeyEntry` object.

<br />

| Parameters ||
|---|---|
| `privateKey` | `PrivateKey`: the `PrivateKey` <br /> |
| `chain` | `Certificate`: an array of `Certificate`s representing the certificate chain. The chain must be ordered and contain a `Certificate` at index 0 corresponding to the private key. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the specified chain has a length of 0, if the specified chain does not contain `Certificate`s of the same type, or if the `PrivateKey` algorithm does not match the algorithm of the `PublicKey` in the end entity `Certificate` (at index 0) |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `privateKey` or `chain` is `null` |

### PrivateKeyEntry

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

```
public PrivateKeyEntry (PrivateKey privateKey, 
                Certificate[] chain, 
                Set<KeyStore.Entry.Attribute> attributes)
```

Constructs a `PrivateKeyEntry` with a `PrivateKey` and
corresponding certificate chain and associated entry attributes.

The specified `chain` and `attributes` are cloned
before they are stored in the new `PrivateKeyEntry` object.

<br />

| Parameters ||
|---|---|
| `privateKey` | `PrivateKey`: the `PrivateKey` <br /> |
| `chain` | `Certificate`: an array of `Certificate`s representing the certificate chain. The chain must be ordered and contain a `Certificate` at index 0 corresponding to the private key. <br /> |
| `attributes` | `Set`: the attributes <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the specified chain has a length of 0, if the specified chain does not contain `Certificate`s of the same type, or if the `PrivateKey` algorithm does not match the algorithm of the `PublicKey` in the end entity `Certificate` (at index 0) |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `privateKey`, `chain` or `attributes` is `null` |

## Public methods

### getAttributes

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

```
public Set<KeyStore.Entry.Attribute> getAttributes ()
```

Retrieves the attributes associated with an entry.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/security/KeyStore.Entry.Attribute>` | an unmodifiable `Set` of attributes, possibly empty <br /> |

### getCertificate

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

```
public Certificate getCertificate ()
```

Gets the end entity `Certificate`
from the certificate chain in this entry.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/cert/Certificate` | the end entity `Certificate` (at index 0) from the certificate chain in this entry. If the certificate is of type X.509, the runtime type of the returned certificate is `X509Certificate`. <br /> |

### getCertificateChain

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

```
public Certificate[] getCertificateChain ()
```

Gets the `Certificate` chain from this entry.

The stored chain is cloned before being returned.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/cert/Certificate` | an array of `Certificate`s corresponding to the certificate chain for the public key. If the certificates are of type X.509, the runtime type of the returned array is `X509Certificate[]`. <br /> |

### getPrivateKey

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

```
public PrivateKey getPrivateKey ()
```

Gets the `PrivateKey` from this entry.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/PrivateKey` | the `PrivateKey` from this entry <br /> |

### toString

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

```
public String toString ()
```

Returns a string representation of this PrivateKeyEntry.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of this PrivateKeyEntry. <br /> |