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

# AttestedKeyPair

*** ** * ** ***

```
class AttestedKeyPair
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.security.AttestedKeyPair](https://developer.android.com/reference/kotlin/android/security/AttestedKeyPair#) |

The `AttestedKeyPair` class contains a `KeyPair` instance of keys generated by Keystore and owned by KeyChain, as well as an attestation record for the key.

Such keys can be obtained by calling android.app.admin.DevicePolicyManager#generateKeyPair.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/security/AttestedKeyPair#AttestedKeyPair(java.security.KeyPair,%20kotlin.collections.MutableList)(keyPair: https://developer.android.com/reference/kotlin/java/security/KeyPair.html#?, attestationRecord: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html<https://developer.android.com/reference/kotlin/java/security/cert/Certificate.html#!>)` Public constructor for creating a new instance (useful for testing). |

| Public methods ||
|---|---|
| [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[Certificate](https://developer.android.com/reference/kotlin/java/security/cert/Certificate.html#)!\> | `https://developer.android.com/reference/kotlin/android/security/AttestedKeyPair#getAttestationRecord()()` Returns the attestation record for the key pair in this instance. |
| [KeyPair](https://developer.android.com/reference/kotlin/java/security/KeyPair.html#)? | `https://developer.android.com/reference/kotlin/android/security/AttestedKeyPair#getKeyPair()()` Returns the generated key pair associated with the attestation record in this instance. |

## Public constructors

### AttestedKeyPair

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

```
AttestedKeyPair(
    keyPair: KeyPair?, 
    attestationRecord: MutableList<Certificate!>)
```

Public constructor for creating a new instance (useful for testing).

| Parameters ||
|---|---|
| `keyPair` | [KeyPair](https://developer.android.com/reference/kotlin/java/security/KeyPair.html#)?: the key pair associated with the attestation record. This value may be `null`. |
| `attestationRecord` | [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[Certificate](https://developer.android.com/reference/kotlin/java/security/cert/Certificate.html#)!\>: attestation record for the provided key pair. This value cannot be `null`. |

## Public methods

### getAttestationRecord

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

```
fun getAttestationRecord(): MutableList<Certificate!>
```

Returns the attestation record for the key pair in this instance. The attestation record is a chain of certificates. The leaf certificate links to the public key of this key pair and other properties of the key or the device. If the key is in secure hardware, and if the secure hardware supports attestation, the leaf certificate will be signed by a chain of certificates rooted at a trustworthy CA key. Otherwise the chain will be rooted at an untrusted certificate. The attestation record could be for properties of the key, or include device identifiers. See `https://developer.android.com/reference/kotlin/android/security/keystore/KeyGenParameterSpec.Builder#setAttestationChallenge(kotlin.ByteArray)` and [Key Attestation](https://developer.android.com/training/articles/security-key-attestation.html) for the format of the attestation record inside the certificate.

| Return ||
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html<https://developer.android.com/reference/kotlin/java/security/cert/Certificate.html#!>` | This value cannot be `null`. |

### getKeyPair

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

```
fun getKeyPair(): KeyPair?
```

Returns the generated key pair associated with the attestation record in this instance.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/java/security/KeyPair.html#?` | This value may be `null`. |