# KeyRep

public class **KeyRep** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [Serializable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Serializable.html) 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://developers.google.com/j2objc/javadoc/jre/platform/serialization/spec/security.html)
of the Serialization Specification for more information.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Key.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyFactory.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/crypto/spec/SecretKeySpec.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/spec/X509EncodedKeySpec.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/spec/PKCS8EncodedKeySpec.html`

### Nested Class Summary

|---|---|---|---|
| enum | [KeyRep.Type](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyRep.Type.html) || Key type. |

### Public Constructor Summary

|---|---|
|   | [KeyRep](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyRep.html#KeyRep(java.security.KeyRep.Type,%20java.lang.String,%20java.lang.String,%20byte[]))([KeyRep.Type](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyRep.Type.html) type, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) format, byte\[\] encoded) Construct the alternate Key class. |

### Protected Method Summary

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [readResolve](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyRep.html#readResolve())() Resolve the Key object. |

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

## Public Constructors

#### public
**KeyRep**
([KeyRep.Type](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/KeyRep.Type.html) type, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) algorithm, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) format, byte\[\] encoded)

Construct the alternate Key class.

<br />

##### Parameters

| type | either one of Type.SECRET, Type.PUBLIC, or Type.PRIVATE |
| algorithm | the algorithm returned from `Key.getAlgorithm()` |
| format | the encoding format returned from `Key.getFormat()` |
| encoded | the encoded bytes returned from `Key.getEncoded()` |
|---|---|

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if type is `null`, if algorithm is `null`, if format is `null`, or if encoded is `null` |
|---|---|

## Protected Methods

#### protected [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)
**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 />

##### Returns

- the resolved Key object

##### Throws

| [ObjectStreamException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/ObjectStreamException.html) | 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 |
|---|---|