# KeyPair

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/KeyPair#pubctors) \| [Methods](https://developer.android.com/reference/java/security/KeyPair#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/KeyPair#inhmethods)  

# KeyPair


`
public

final

class
KeyPair
`


`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


`

`


implements

`[Serializable](https://developer.android.com/reference/java/io/Serializable)`


`

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

<br />

*** ** * ** ***

This class is a simple holder for a key pair (a public key and a
private key). It does not enforce any security, and, when initialized,
should be treated like a PrivateKey.  
**See also:**

- [PublicKey](https://developer.android.com/reference/java/security/PublicKey)
- [PrivateKey](https://developer.android.com/reference/java/security/PrivateKey)

## Summary

|                                                                                                                                                                                        ### Public constructors                                                                                                                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[KeyPair](https://developer.android.com/reference/java/security/KeyPair#KeyPair(java.security.PublicKey,%20java.security.PrivateKey))`(`[PublicKey](https://developer.android.com/reference/java/security/PublicKey)` publicKey, `[PrivateKey](https://developer.android.com/reference/java/security/PrivateKey)` privateKey) ` Constructs a key pair from the given public key and private key. |

|                                                                                                                   ### Public methods                                                                                                                   ||
|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[PrivateKey](https://developer.android.com/reference/java/security/PrivateKey) | ` `[getPrivate](https://developer.android.com/reference/java/security/KeyPair#getPrivate())`() ` Returns a reference to the private key component of this key pair. |
| ` `[PublicKey](https://developer.android.com/reference/java/security/PublicKey)   | ` `[getPublic](https://developer.android.com/reference/java/security/KeyPair#getPublic())`() ` Returns a reference to the public key component of this key pair.    |

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

## Public constructors

### KeyPair

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

```
public KeyPair (PublicKey publicKey, 
                PrivateKey privateKey)
```

Constructs a key pair from the given public key and private key.

Note that this constructor only stores references to the public
and private key components in the generated key pair. This is safe,
because `Key` objects are immutable.

<br />

|                     Parameters                      ||
|--------------|---------------------------------------|
| `publicKey`  | `PublicKey`: the public key. <br />   |
| `privateKey` | `PrivateKey`: the private key. <br /> |

## Public methods

### getPrivate

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

```
public PrivateKey getPrivate ()
```

Returns a reference to the private key component of this key pair.

<br />

|                                                        Returns                                                         ||
|--------------------------------------------------------------------------------|----------------------------------------|
| [PrivateKey](https://developer.android.com/reference/java/security/PrivateKey) | a reference to the private key. <br /> |

### getPublic

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

```
public PublicKey getPublic ()
```

Returns a reference to the public key component of this key pair.

<br />

|                                                       Returns                                                       ||
|------------------------------------------------------------------------------|---------------------------------------|
| [PublicKey](https://developer.android.com/reference/java/security/PublicKey) | a reference to the public key. <br /> |