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

# KeyRep

` public class KeyRep `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/io/Serializable `

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

<br />

*** ** * ** ***

Standardized representation for serialized Key objects.

Note that a serialized Key may contain sensitive information which should not be exposed in untrusted environments. See the [Security Appendix](https://docs.oracle.com/en/java/javase/17/docs/specs/serialization/security.html) of the Serialization Specification for more information.
**See also:**

- `https://developer.android.com/reference/java/security/Key`
- `https://developer.android.com/reference/java/security/KeyFactory`
- `https://developer.android.com/reference/javax/crypto/spec/SecretKeySpec`
- `https://developer.android.com/reference/java/security/spec/X509EncodedKeySpec`
- `https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/KeyRep#KeyRep(java.security.KeyRep.Type,%20java.lang.String,%20java.lang.String,%20byte[])(https://developer.android.com/reference/java/security/KeyRep.Type type, https://developer.android.com/reference/java/lang/String algorithm, https://developer.android.com/reference/java/lang/String format, byte[] encoded) ` Construct the alternate Key class. |

| ### Protected methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/security/KeyRep#readResolve()() ` Resolve the Key object. |

### 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*.

## Public constructors

### KeyRep

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

```
public KeyRep (KeyRep.Type type, 
                String algorithm, 
                String format, 
                byte[] encoded)
```

Construct the alternate Key class.

<br />

| Parameters ||
|---|---|
| `type` | `KeyRep.Type`: either one of Type.SECRET, Type.PUBLIC, or Type.PRIVATE <br /> |
| `algorithm` | `String`: the algorithm returned from `Key.getAlgorithm()` <br /> |
| `format` | `String`: the encoding format returned from `Key.getFormat()` <br /> |
| `encoded` | `byte`: the encoded bytes returned from `Key.getEncoded()` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if type is `null`, if algorithm is `null`, if format is `null`, or if encoded is `null` |

## Protected methods

### readResolve

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

```
protected Object readResolve ()
```

Resolve the Key object.

This method supports three Type/format combinations:

- Type.SECRET/"RAW" - returns a SecretKeySpec object constructed using encoded key bytes and algorithm
- Type.PUBLIC/"X.509" - gets a KeyFactory instance for the key algorithm, constructs an X509EncodedKeySpec with the encoded key bytes, and generates a public key from the spec
- Type.PRIVATE/"PKCS#8" - gets a KeyFactory instance for the key algorithm, constructs a PKCS8EncodedKeySpec with the encoded key bytes, and generates a private key from the spec

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | the resolved Key object <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/ObjectStreamException` | if the Type/format combination is unrecognized, if the algorithm, key format, or encoded key bytes are unrecognized/invalid, of if the resolution of the key fails for any reason |