Package javax.crypto
Class EncryptedPrivateKeyInfo
java.lang.Object
javax.crypto.EncryptedPrivateKeyInfo
public class EncryptedPrivateKeyInfo extends Object
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 }
-
Constructor Summary
Constructors Constructor Description EncryptedPrivateKeyInfo(byte[] encoded)Creates anEncryptedPrivateKeyInfoinstance from its encoded representation by parsing it.EncryptedPrivateKeyInfo(String encryptionAlgorithmName, byte[] encryptedData)Creates anEncryptedPrivateKeyInfoinstance from an algorithm name and its encrypted data.EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData)Creates anEncryptedPrivateKeyInfoinstance from the encryption algorithm parameters an its encrypted data. -
Method Summary
Modifier and Type Method Description StringgetAlgName()Returns the name of the encryption algorithm.AlgorithmParametersgetAlgParameters()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.PKCS8EncodedKeySpecgetKeySpec(Key decryptKey)Returns thePKCS8EncodedKeySpecobject extracted from the encrypted data.PKCS8EncodedKeySpecgetKeySpec(Key decryptKey, String providerName)Returns thePKCS8EncodedKeySpecobject extracted from the encrypted data.PKCS8EncodedKeySpecgetKeySpec(Key decryptKey, Provider provider)Returns thePKCS8EncodedKeySpecobject extracted from the encrypted data.PKCS8EncodedKeySpecgetKeySpec(Cipher cipher)Returns thePKCS8EncodedKeySpecobject extracted from the encrypted data.
-
Constructor Details
-
EncryptedPrivateKeyInfo
Creates anEncryptedPrivateKeyInfoinstance from its encoded representation by parsing it.- Parameters:
encoded- the encoded representation of this object- Throws:
IOException- if parsing the encoded representation fails.NullPointerException- ifencodedisnull.
-
EncryptedPrivateKeyInfo
public EncryptedPrivateKeyInfo(String encryptionAlgorithmName, byte[] encryptedData) throws NoSuchAlgorithmExceptionCreates anEncryptedPrivateKeyInfoinstance from an algorithm name and its encrypted data.- Parameters:
encryptionAlgorithmName- the name of an algorithm.encryptedData- the encrypted data.- Throws:
NoSuchAlgorithmException- if theencrAlgNameis not a supported algorithm.NullPointerException- ifencrAlgNameorencryptedDataisnull.IllegalArgumentException- ifencryptedDatais empty.
-
EncryptedPrivateKeyInfo
public EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData) throws NoSuchAlgorithmExceptionCreates anEncryptedPrivateKeyInfoinstance from the encryption algorithm parameters an its encrypted data.- Parameters:
algParams- the encryption algorithm parameters.encryptedData- the encrypted data.- Throws:
NoSuchAlgorithmException- if the algorithm name of the specifiedalgParamsparameter is not supported.NullPointerException- ifalgParamsorencryptedDataisnull.
-
-
Method Details
-
getAlgName
Returns the name of the encryption algorithm.- Returns:
- the name of the encryption algorithm.
-
getAlgParameters
Returns the parameters used by the encryption algorithm.- Returns:
- the parameters used by the encryption algorithm.
-
getEncryptedData
public byte[] getEncryptedData()Returns the encrypted data of this key.- Returns:
- the encrypted data of this key, each time this method is called a new array is returned.
-
getKeySpec
Returns thePKCS8EncodedKeySpecobject extracted from the encrypted data.The cipher must be initialize in either
Cipher.DECRYPT_MODEorCipher.UNWRAP_MODEwith the same parameters and key used for encrypting this.- Parameters:
cipher- the cipher initialized for decrypting the encrypted data.- Returns:
- the extracted
PKCS8EncodedKeySpec. - Throws:
InvalidKeySpecException- if the specified cipher is not suited to decrypt the encrypted data.NullPointerException- ifcipherisnull.
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey) throws NoSuchAlgorithmException, InvalidKeyExceptionReturns thePKCS8EncodedKeySpecobject extracted from the encrypted data.- Parameters:
decryptKey- the key to decrypt the encrypted data with.- Returns:
- the extracted
PKCS8EncodedKeySpec. - Throws:
NoSuchAlgorithmException- if no usable cipher can be found to decrypt the encrypted data.InvalidKeyException- ifdecryptKeyis not usable to decrypt the encrypted data.NullPointerException- ifdecryptKeyisnull.
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, String providerName) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyExceptionReturns thePKCS8EncodedKeySpecobject extracted from the encrypted data.- Parameters:
decryptKey- the key to decrypt the encrypted data with.providerName- the name of a provider whose cipher implementation should be used.- Returns:
- the extracted
PKCS8EncodedKeySpec. - Throws:
NoSuchProviderException- if no provider withproviderNamecan be found.NoSuchAlgorithmException- if no usable cipher can be found to decrypt the encrypted data.InvalidKeyException- ifdecryptKeyis not usable to decrypt the encrypted data.NullPointerException- ifdecryptKeyorproviderNameisnull.
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, Provider provider) throws NoSuchAlgorithmException, InvalidKeyExceptionReturns thePKCS8EncodedKeySpecobject extracted from the encrypted data.- Parameters:
decryptKey- the key to decrypt the encrypted data with.provider- the provider whose cipher implementation should be used.- Returns:
- the extracted
PKCS8EncodedKeySpec. - Throws:
NoSuchAlgorithmException- if no usable cipher can be found to decrypt the encrypted data.InvalidKeyException- ifdecryptKeyis not usable to decrypt the encrypted data.NullPointerException- ifdecryptKeyorproviderisnull.
-
getEncoded
Returns the ASN.1 encoded representation of this object.- Returns:
- the ASN.1 encoded representation of this object.
- Throws:
IOException- if encoding this object fails.
-