# EncryptedPrivateKeyInfo

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

# EncryptedPrivateKeyInfo

`
public


class
EncryptedPrivateKeyInfo
`  
`

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


``


`

|---|--------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | javax.crypto.EncryptedPrivateKeyInfo |

<br />

*** ** * ** ***

This class implements the`EncryptedPrivateKeyInfo`type as defined in PKCS #8.

Its ASN.1 definition is as follows:  

```
 EncryptedPrivateKeyInfo ::=  SEQUENCE {
     encryptionAlgorithm   AlgorithmIdentifier,
     encryptedData   OCTET STRING }

 AlgorithmIdentifier  ::=  SEQUENCE  {
     algorithm              OBJECT IDENTIFIER,
     parameters             ANY DEFINED BY algorithm OPTIONAL  }
 
```

<br />

**See also:**

- [PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec)

## Summary

|                                                                                                                                                                                                     ### Public constructors                                                                                                                                                                                                      ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[EncryptedPrivateKeyInfo](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#EncryptedPrivateKeyInfo(byte[]))`(byte[] encoded) ` Constructs (i.e., parses) an`EncryptedPrivateKeyInfo`from its ASN.1 encoding.                                                                                                                                                                                   |
| ` `[EncryptedPrivateKeyInfo](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#EncryptedPrivateKeyInfo(java.lang.String,%20byte[]))`(`[String](https://developer.android.com/reference/java/lang/String)` algName, byte[] encryptedData) ` Constructs an`EncryptedPrivateKeyInfo`from the encryption algorithm name and the encrypted data.                                                        |
| ` `[EncryptedPrivateKeyInfo](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#EncryptedPrivateKeyInfo(java.security.AlgorithmParameters,%20byte[]))`(`[AlgorithmParameters](https://developer.android.com/reference/java/security/AlgorithmParameters)` algParams, byte[] encryptedData) ` Constructs an`EncryptedPrivateKeyInfo`from the encryption algorithm parameters and the encrypted data. |

|                                                                                                                                                                                                                                                       ### Public methods                                                                                                                                                                                                                                                        ||
|----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[String](https://developer.android.com/reference/java/lang/String)                                    | ` `[getAlgName](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#getAlgName())`() ` Returns the encryption algorithm.                                                                                                                                                                                                                                                                     |
| ` `[AlgorithmParameters](https://developer.android.com/reference/java/security/AlgorithmParameters)      | ` `[getAlgParameters](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#getAlgParameters())`() ` Returns the algorithm parameters used by the encryption algorithm.                                                                                                                                                                                                                        |
| ` byte[]`                                                                                                | ` `[getEncoded](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#getEncoded())`() ` Returns the ASN.1 encoding of this object.                                                                                                                                                                                                                                                            |
| ` byte[]`                                                                                                | ` `[getEncryptedData](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#getEncryptedData())`() ` Returns the encrypted data.                                                                                                                                                                                                                                                               |
| ` `[PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec) | ` `[getKeySpec](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#getKeySpec(java.security.Key))`(`[Key](https://developer.android.com/reference/java/security/Key)` decryptKey) ` Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.                                                                                                                  |
| ` `[PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec) | ` `[getKeySpec](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#getKeySpec(java.security.Key,%20java.security.Provider))`(`[Key](https://developer.android.com/reference/java/security/Key)` decryptKey, `[Provider](https://developer.android.com/reference/java/security/Provider)` provider) ` Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it. |
| ` `[PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec) | ` `[getKeySpec](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#getKeySpec(java.security.Key,%20java.lang.String))`(`[Key](https://developer.android.com/reference/java/security/Key)` decryptKey, `[String](https://developer.android.com/reference/java/lang/String)` providerName) ` Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.           |
| ` `[PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec) | ` `[getKeySpec](https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo#getKeySpec(javax.crypto.Cipher))`(`[Cipher](https://developer.android.com/reference/javax/crypto/Cipher)` cipher) ` Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.                                                                                                               |

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

### EncryptedPrivateKeyInfo

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

```
public EncryptedPrivateKeyInfo (byte[] encoded)
```

Constructs (i.e., parses) an`EncryptedPrivateKeyInfo`from its ASN.1 encoding.

<br />

|                                                                  Parameters                                                                   ||
|-----------|------------------------------------------------------------------------------------------------------------------------------------|
| `encoded` | `byte`: the ASN.1 encoding of this object. The contents of the array are copied to protect against subsequent modification. <br /> |

|                                                                      Throws                                                                      ||
|------------------------------------------------------------------------------------------------|--------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the`encoded`is null.                          |
| [IOException](https://developer.android.com/reference/java/io/IOException)                     | if error occurs when parsing the ASN.1 encoding. |

### EncryptedPrivateKeyInfo

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

```
public EncryptedPrivateKeyInfo (String algName, 
                byte[] encryptedData)
```

Constructs an`EncryptedPrivateKeyInfo`from the encryption algorithm name and the encrypted data.

Note: This constructor will use null as the value of the algorithm parameters. If the encryption algorithm has parameters whose value is not null, a different constructor, e.g. EncryptedPrivateKeyInfo(AlgorithmParameters, byte\[\]), should be used.

<br />

|                                                                                                                                      Parameters                                                                                                                                       ||
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `algName`       | `String`: encryption algorithm name. See Appendix A in the[Java Cryptography Architecture Reference Guide](https://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA)for information about standard Cipher algorithm names. <br /> |
| `encryptedData` | `byte`: encrypted data. The contents of`encrypedData`are copied to protect against subsequent modification when constructing this object. <br />                                                                                                                     |

|                                                                         Throws                                                                         ||
|------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)             | if`algName`or`encryptedData`is null.       |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException)     | if`encryptedData`is empty, i.e. 0-length.  |
| [NoSuchAlgorithmException](https://developer.android.com/reference/java/security/NoSuchAlgorithmException) | if the specified algName is not supported. |

### EncryptedPrivateKeyInfo

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

```
public EncryptedPrivateKeyInfo (AlgorithmParameters algParams, 
                byte[] encryptedData)
```

Constructs an`EncryptedPrivateKeyInfo`from the encryption algorithm parameters and the encrypted data.

<br />

|                                                                                                                             Parameters                                                                                                                              ||
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `algParams`     | `AlgorithmParameters`: the algorithm parameters for the encryption algorithm.`algParams.getEncoded()`should return the ASN.1 encoded bytes of the`parameters`field of the`AlgorithmIdentifer`component of the`EncryptedPrivateKeyInfo`type. <br /> |
| `encryptedData` | `byte`: encrypted data. The contents of`encrypedData`are copied to protect against subsequent modification when constructing this object. <br />                                                                                                   |

|                                                                                           Throws                                                                                            ||
|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)             | if`algParams`or`encryptedData`is null.                                          |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException)     | if`encryptedData`is empty, i.e. 0-length.                                       |
| [NoSuchAlgorithmException](https://developer.android.com/reference/java/security/NoSuchAlgorithmException) | if the specified algName of the specified`algParams`parameter is not supported. |

## Public methods

### getAlgName

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

```
public String getAlgName ()
```

Returns the encryption algorithm.

Note: Standard name is returned instead of the specified one in the constructor when such mapping is available. See Appendix A in the[Java Cryptography Architecture Reference Guide](https://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html#AppA)for information about standard Cipher algorithm names.

<br />

|                                                  Returns                                                  ||
|--------------------------------------------------------------------|---------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the encryption algorithm name. <br /> |

### getAlgParameters

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

```
public AlgorithmParameters getAlgParameters ()
```

Returns the algorithm parameters used by the encryption algorithm.

<br />

|                                                              Returns                                                               ||
|--------------------------------------------------------------------------------------------------|----------------------------------|
| [AlgorithmParameters](https://developer.android.com/reference/java/security/AlgorithmParameters) | the algorithm parameters. <br /> |

### getEncoded

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

```
public byte[] getEncoded ()
```

Returns the ASN.1 encoding of this object.

<br />

|                                          Returns                                          ||
|----------|---------------------------------------------------------------------------------|
| `byte[]` | the ASN.1 encoding. Returns a new array each time this method is called. <br /> |

|                                                              Throws                                                               ||
|----------------------------------------------------------------------------|-------------------------------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if error occurs when constructing its ASN.1 encoding. |

### getEncryptedData

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

```
public byte[] getEncryptedData ()
```

Returns the encrypted data.

<br />

|                                          Returns                                          ||
|----------|---------------------------------------------------------------------------------|
| `byte[]` | the encrypted data. Returns a new array each time this method is called. <br /> |

### getKeySpec

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

```
public PKCS8EncodedKeySpec getKeySpec (Key decryptKey)
```

Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.

<br />

|                               Parameters                                ||
|--------------|-----------------------------------------------------------|
| `decryptKey` | `Key`: key used for decrypting the encrypted data. <br /> |

|                                                                    Returns                                                                    ||
|-------------------------------------------------------------------------------------------------------|----------------------------------------|
| [PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec) | the PKCS8EncodedKeySpec object. <br /> |

|                                                                                                            Throws                                                                                                            ||
|------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)             | if`decryptKey`is null.                                                                                           |
| [NoSuchAlgorithmException](https://developer.android.com/reference/java/security/NoSuchAlgorithmException) | if cannot find appropriate cipher to decrypt the encrypted data.                                                 |
| [InvalidKeyException](https://developer.android.com/reference/java/security/InvalidKeyException)           | if`decryptKey`cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec. |

### getKeySpec

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

```
public PKCS8EncodedKeySpec getKeySpec (Key decryptKey, 
                Provider provider)
```

Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.

<br />

|                                           Parameters                                            ||
|--------------|-----------------------------------------------------------------------------------|
| `decryptKey` | `Key`: key used for decrypting the encrypted data. <br />                         |
| `provider`   | `Provider`: the name of provider whose Cipher implementation will be used. <br /> |

|                                                                    Returns                                                                    ||
|-------------------------------------------------------------------------------------------------------|----------------------------------------|
| [PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec) | the PKCS8EncodedKeySpec object. <br /> |

|                                                                                                            Throws                                                                                                            ||
|------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)             | if`decryptKey`or`provider`is null.                                                                               |
| [NoSuchAlgorithmException](https://developer.android.com/reference/java/security/NoSuchAlgorithmException) | if cannot find appropriate cipher to decrypt the encrypted data in`provider`.                                    |
| [InvalidKeyException](https://developer.android.com/reference/java/security/InvalidKeyException)           | if`decryptKey`cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec. |

### getKeySpec

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

```
public PKCS8EncodedKeySpec getKeySpec (Key decryptKey, 
                String providerName)
```

Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.

<br />

|                                           Parameters                                            ||
|----------------|---------------------------------------------------------------------------------|
| `decryptKey`   | `Key`: key used for decrypting the encrypted data. <br />                       |
| `providerName` | `String`: the name of provider whose Cipher implementation will be used. <br /> |

|                                                                    Returns                                                                    ||
|-------------------------------------------------------------------------------------------------------|----------------------------------------|
| [PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec) | the PKCS8EncodedKeySpec object. <br /> |

|                                                                                                            Throws                                                                                                            ||
|------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)             | if`decryptKey`or`providerName`is null.                                                                           |
| [NoSuchProviderException](https://developer.android.com/reference/java/security/NoSuchProviderException)   | if no provider`providerName`is registered.                                                                       |
| [NoSuchAlgorithmException](https://developer.android.com/reference/java/security/NoSuchAlgorithmException) | if cannot find appropriate cipher to decrypt the encrypted data.                                                 |
| [InvalidKeyException](https://developer.android.com/reference/java/security/InvalidKeyException)           | if`decryptKey`cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec. |

### getKeySpec

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

```
public PKCS8EncodedKeySpec getKeySpec (Cipher cipher)
```

Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.  
Note: In order to successfully retrieve the enclosed PKCS8EncodedKeySpec object,`cipher`needs to be initialized to either Cipher.DECRYPT_MODE or Cipher.UNWRAP_MODE, with the same key and parameters used for generating the encrypted data.

<br />

|                                                   Parameters                                                   ||
|----------|------------------------------------------------------------------------------------------------------|
| `cipher` | `Cipher`: the initialized cipher object which will be used for decrypting the encrypted data. <br /> |

|                                                                    Returns                                                                    ||
|-------------------------------------------------------------------------------------------------------|----------------------------------------|
| [PKCS8EncodedKeySpec](https://developer.android.com/reference/java/security/spec/PKCS8EncodedKeySpec) | the PKCS8EncodedKeySpec object. <br /> |

|                                                                                                                 Throws                                                                                                                 ||
|---------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)                | if`cipher`is null.                                                                                                      |
| [InvalidKeySpecException](https://developer.android.com/reference/java/security/spec/InvalidKeySpecException) | if the given cipher is inappropriate for the encrypted data or the encrypted data is corrupted and cannot be decrypted. |