Android APIs
public class

EncryptedPrivateKeyInfo

extends Object
java.lang.Object
   ↳ javax.crypto.EncryptedPrivateKeyInfo

Class Overview

This class implements the EncryptedPrivateKeyInfo ASN.1 type as specified in PKCS #8 - Private-Key Information Syntax Standard.

The definition of ASN.1 is as follows:

EncryptedPrivateKeyInfo ::= SEQUENCE {
encryptionAlgorithm AlgorithmIdentifier,
encryptedData OCTET STRING }
AlgorithmIdentifier ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameters ANY DEFINED BY algorithm OPTIONAL }

Summary

Public Constructors
EncryptedPrivateKeyInfo(byte[] encoded)
Creates an EncryptedPrivateKeyInfo instance from its encoded representation by parsing it.
EncryptedPrivateKeyInfo(String encryptionAlgorithmName, byte[] encryptedData)
Creates an EncryptedPrivateKeyInfo instance from an algorithm name and its encrypted data.
EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData)
Creates an EncryptedPrivateKeyInfo instance from the encryption algorithm parameters an its encrypted data.
Public Methods
String getAlgName()
Returns the name of the encryption algorithm.
AlgorithmParameters getAlgParameters()
Returns the parameters used by the encryption algorithm.
byte[] getEncoded()
Returns the ASN.1 encoded representation of this object.
byte[] getEncryptedData()
Returns the encrypted data of this key.
PKCS8EncodedKeySpec getKeySpec(Cipher cipher)
Returns the PKCS8EncodedKeySpec object extracted from the encrypted data.
PKCS8EncodedKeySpec getKeySpec(Key decryptKey)
Returns the PKCS8EncodedKeySpec object extracted from the encrypted data.
PKCS8EncodedKeySpec getKeySpec(Key decryptKey, String providerName)
Returns the PKCS8EncodedKeySpec object extracted from the encrypted data.
PKCS8EncodedKeySpec getKeySpec(Key decryptKey, Provider provider)
Returns the PKCS8EncodedKeySpec object extracted from the encrypted data.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public EncryptedPrivateKeyInfo (byte[] encoded)

Added in API level 1

Creates an EncryptedPrivateKeyInfo instance from its encoded representation by parsing it.

Parameters
encoded byte: the encoded representation of this object
Throws
IOException if parsing the encoded representation fails.
NullPointerException if encoded is null.

public EncryptedPrivateKeyInfo (String encryptionAlgorithmName, byte[] encryptedData)

Added in API level 1

Creates an EncryptedPrivateKeyInfo instance from an algorithm name and its encrypted data.

Parameters
encryptionAlgorithmName String: the name of an algorithm.
encryptedData byte: the encrypted data.
Throws
NoSuchAlgorithmException if the encrAlgName is not a supported algorithm.
NullPointerException if encrAlgName or encryptedData is null.
IllegalArgumentException if encryptedData is empty.

public EncryptedPrivateKeyInfo (AlgorithmParameters algParams, byte[] encryptedData)

Added in API level 1

Creates an EncryptedPrivateKeyInfo instance from the encryption algorithm parameters an its encrypted data.

Parameters
algParams AlgorithmParameters: the encryption algorithm parameters.
encryptedData byte: the encrypted data.
Throws
NoSuchAlgorithmException if the algorithm name of the specified algParams parameter is not supported.
NullPointerException if algParams or encryptedData is null.

Public Methods

public String getAlgName ()

Added in API level 1

Returns the name of the encryption algorithm.

Returns
String the name of the encryption algorithm.

public AlgorithmParameters getAlgParameters ()

Added in API level 1

Returns the parameters used by the encryption algorithm.

Returns
AlgorithmParameters the parameters used by the encryption algorithm.

public byte[] getEncoded ()

Added in API level 1

Returns the ASN.1 encoded representation of this object.

Returns
byte[] the ASN.1 encoded representation of this object.
Throws
IOException if encoding this object fails.

public byte[] getEncryptedData ()

Added in API level 1

Returns the encrypted data of this key.

Returns
byte[] the encrypted data of this key, each time this method is called a new array is returned.

public PKCS8EncodedKeySpec getKeySpec (Cipher cipher)

Added in API level 1

Returns the PKCS8EncodedKeySpec object extracted from the encrypted data.

The cipher must be initialize in either Cipher.DECRYPT_MODE or Cipher.UNWRAP_MODE with the same parameters and key used for encrypting this.

Parameters
cipher Cipher: the cipher initialized for decrypting the encrypted data.
Returns
PKCS8EncodedKeySpec the extracted PKCS8EncodedKeySpec.
Throws
InvalidKeySpecException if the specified cipher is not suited to decrypt the encrypted data.
NullPointerException if cipher is null.

public PKCS8EncodedKeySpec getKeySpec (Key decryptKey)

Added in API level 1

Returns the PKCS8EncodedKeySpec object extracted from the encrypted data.

Parameters
decryptKey Key: the key to decrypt the encrypted data with.
Returns
PKCS8EncodedKeySpec the extracted PKCS8EncodedKeySpec.
Throws
NoSuchAlgorithmException if no usable cipher can be found to decrypt the encrypted data.
InvalidKeyException if decryptKey is not usable to decrypt the encrypted data.
NullPointerException if decryptKey is null.

public PKCS8EncodedKeySpec getKeySpec (Key decryptKey, String providerName)

Added in API level 1

Returns the PKCS8EncodedKeySpec object extracted from the encrypted data.

Parameters
decryptKey Key: the key to decrypt the encrypted data with.
providerName String: the name of a provider whose cipher implementation should be used.
Returns
PKCS8EncodedKeySpec the extracted PKCS8EncodedKeySpec.
Throws
NoSuchProviderException if no provider with providerName can be found.
NoSuchAlgorithmException if no usable cipher can be found to decrypt the encrypted data.
InvalidKeyException if decryptKey is not usable to decrypt the encrypted data.
NullPointerException if decryptKey or providerName is null .

public PKCS8EncodedKeySpec getKeySpec (Key decryptKey, Provider provider)

Added in API level 1

Returns the PKCS8EncodedKeySpec object extracted from the encrypted data.

Parameters
decryptKey Key: the key to decrypt the encrypted data with.
provider Provider: the provider whose cipher implementation should be used.
Returns
PKCS8EncodedKeySpec the extracted PKCS8EncodedKeySpec.
Throws
NoSuchAlgorithmException if no usable cipher can be found to decrypt the encrypted data.
InvalidKeyException if decryptKey is not usable to decrypt the encrypted data.
NullPointerException if decryptKey or provider is null.