JavaTM 2 Platform
Std. Ed. v1.4.0

javax.crypto
Class EncryptedPrivateKeyInfo

java.lang.Object
  |
  +--javax.crypto.EncryptedPrivateKeyInfo

public class EncryptedPrivateKeyInfo
extends Object

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  }
 

Since:
1.4
See Also:
PKCS8EncodedKeySpec

Constructor Summary
EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData)
          Constructs an EncryptedPrivateKeyInfo from the encryption algorithm parameters and the encrypted data.
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.
 
Method Summary
 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 a copy of the encrypted data.
 PKCS8EncodedKeySpec getKeySpec(Cipher c)
          Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncryptedPrivateKeyInfo

public EncryptedPrivateKeyInfo(byte[] encoded)
                        throws IOException
Constructs (i.e., parses) an EncryptedPrivateKeyInfo from its ASN.1 encoding.

Parameters:
encoded - the ASN.1 encoding of this object.
Throws:
NullPointerException - if the encoded is null.
IOException - if error occurs when parsing the ASN.1 encoding.

EncryptedPrivateKeyInfo

public EncryptedPrivateKeyInfo(String algName,
                               byte[] encryptedData)
                        throws NoSuchAlgorithmException
Constructs an EncryptedPrivateKeyInfo from the encryption algorithm name and the encrypted data.

Note: the encrypedData is cloned when constructing this object. If encryption algorithm has associated parameters use the constructor with AlgorithmParameters as the parameter.

Parameters:
algName - algorithm name.
encryptedData - encrypted data.
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

public EncryptedPrivateKeyInfo(AlgorithmParameters algParams,
                               byte[] encryptedData)
                        throws NoSuchAlgorithmException
Constructs an EncryptedPrivateKeyInfo from the encryption algorithm parameters and the encrypted data.

Note: the encrypedData is cloned when constructing this object.

Parameters:
algParams - 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 - encrypted data.
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.
Method Detail

getAlgName

public String getAlgName()
Returns the encryption algorithm.

Returns:
the algorithm name.

getAlgParameters

public AlgorithmParameters getAlgParameters()
Returns the algorithm parameters used by the encryption algorithm.

Returns:
the algorithm parameters.

getEncryptedData

public byte[] getEncryptedData()
Returns a copy of the encrypted data.

Returns:
a copy of the encrypted data.

getKeySpec

public PKCS8EncodedKeySpec getKeySpec(Cipher c)
                               throws InvalidKeySpecException
Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.

Returns:
the PKCS8EncodedKeySpec object.
Throws:
InvalidKeySpecException - if the given cipher is inappropriate for the encrypted data or the encrypted data is corrupted and cannot be decrypted.

getEncoded

public byte[] getEncoded()
                  throws IOException
Returns the ASN.1 encoding of this object.

Returns:
the ASN.1 encoding.
Throws:
IOException - if error occurs when constructing its ASN.1 encoding.

JavaTM 2 Platform
Std. Ed. v1.4.0

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.