Skip to content

Most visited

Recently visited

navigation

EncryptedPrivateKeyInfo

public class EncryptedPrivateKeyInfo
extends Object

java.lang.Object
   ↳ javax.crypto.EncryptedPrivateKeyInfo


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  }
 

See also:

Summary

Public constructors

EncryptedPrivateKeyInfo(byte[] encoded)

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

EncryptedPrivateKeyInfo(String algName, byte[] encryptedData)

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

EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData)

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

Public methods

String getAlgName()

Returns the encryption algorithm.

AlgorithmParameters getAlgParameters()

Returns the algorithm parameters used by the encryption algorithm.

byte[] getEncoded()

Returns the ASN.1 encoding of this object.

byte[] getEncryptedData()

Returns the encrypted data.

PKCS8EncodedKeySpec getKeySpec(Key decryptKey)

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

PKCS8EncodedKeySpec getKeySpec(Key decryptKey, Provider provider)

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

PKCS8EncodedKeySpec getKeySpec(Key decryptKey, String providerName)

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

PKCS8EncodedKeySpec getKeySpec(Cipher cipher)

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

Inherited methods

From class java.lang.Object

Public constructors

EncryptedPrivateKeyInfo

Added in API level 1
EncryptedPrivateKeyInfo (byte[] encoded)

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

Parameters
encoded byte: the ASN.1 encoding of this object. The contents of the array are copied to protect against subsequent modification.
Throws
NullPointerException if the encoded is null.
IOException if error occurs when parsing the ASN.1 encoding.

EncryptedPrivateKeyInfo

Added in API level 1
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.

Parameters
algName String: encryption algorithm name. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard Cipher algorithm names.
encryptedData byte: encrypted data. The contents of encrypedData are copied to protect against subsequent modification when constructing this object.
Throws
NullPointerException if algName or encryptedData is null.
IllegalArgumentException if encryptedData is empty, i.e. 0-length.
NoSuchAlgorithmException if the specified algName is not supported.

EncryptedPrivateKeyInfo

Added in API level 1
EncryptedPrivateKeyInfo (AlgorithmParameters algParams, 
                byte[] encryptedData)

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

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.
encryptedData byte: encrypted data. The contents of encrypedData are copied to protect against subsequent modification when constructing this object.
Throws
NullPointerException if algParams or encryptedData is null.
IllegalArgumentException if encryptedData is empty, i.e. 0-length.
NoSuchAlgorithmException if the specified algName of the specified algParams parameter is not supported.

Public methods

getAlgName

Added in API level 1
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 for information about standard Cipher algorithm names.

Returns
String the encryption algorithm name.

getAlgParameters

Added in API level 1
AlgorithmParameters getAlgParameters ()

Returns the algorithm parameters used by the encryption algorithm.

Returns
AlgorithmParameters the algorithm parameters.

getEncoded

Added in API level 1
byte[] getEncoded ()

Returns the ASN.1 encoding of this object.

Returns
byte[] the ASN.1 encoding. Returns a new array each time this method is called.
Throws
IOException if error occurs when constructing its ASN.1 encoding.

getEncryptedData

Added in API level 1
byte[] getEncryptedData ()

Returns the encrypted data.

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

getKeySpec

Added in API level 1
PKCS8EncodedKeySpec getKeySpec (Key decryptKey)

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

Parameters
decryptKey Key: key used for decrypting the encrypted data.
Returns
PKCS8EncodedKeySpec the PKCS8EncodedKeySpec object.
Throws
NullPointerException if decryptKey is null.
NoSuchAlgorithmException if cannot find appropriate cipher to decrypt the encrypted data.
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
PKCS8EncodedKeySpec getKeySpec (Key decryptKey, 
                Provider provider)

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

Parameters
decryptKey Key: key used for decrypting the encrypted data.
provider Provider: the name of provider whose Cipher implementation will be used.
Returns
PKCS8EncodedKeySpec the PKCS8EncodedKeySpec object.
Throws
NullPointerException if decryptKey or provider is null.
NoSuchAlgorithmException if cannot find appropriate cipher to decrypt the encrypted data in provider.
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
PKCS8EncodedKeySpec getKeySpec (Key decryptKey, 
                String providerName)

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

Parameters
decryptKey Key: key used for decrypting the encrypted data.
providerName String: the name of provider whose Cipher implementation will be used.
Returns
PKCS8EncodedKeySpec the PKCS8EncodedKeySpec object.
Throws
NullPointerException if decryptKey or providerName is null.
NoSuchProviderException if no provider providerName is registered.
NoSuchAlgorithmException if cannot find appropriate cipher to decrypt the encrypted data.
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
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.

Parameters
cipher Cipher: the initialized cipher object which will be used for decrypting the encrypted data.
Returns
PKCS8EncodedKeySpec the PKCS8EncodedKeySpec object.
Throws
NullPointerException if cipher is null.
InvalidKeySpecException if the given cipher is inappropriate for the encrypted data or the encrypted data is corrupted and cannot be decrypted.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.