EncryptedPrivateKeyInfo (Java SE 15 & JDK 15) (original) (raw)
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:
Constructor Summary
Constructors
Constructor | Description |
---|---|
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. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
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,String providerName) | 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(Cipher cipher) | Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it. |
Methods declared in class java.lang.Object
[clone](../../java/lang/Object.html#clone%28%29), [equals](../../java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../java/lang/Object.html#finalize%28%29), [getClass](../../java/lang/Object.html#getClass%28%29), [hashCode](../../java/lang/Object.html#hashCode%28%29), [notify](../../java/lang/Object.html#notify%28%29), [notifyAll](../../java/lang/Object.html#notifyAll%28%29), [toString](../../java/lang/Object.html#toString%28%29), [wait](../../java/lang/Object.html#wait%28%29), [wait](../../java/lang/Object.html#wait%28long%29), [wait](../../java/lang/Object.html#wait%28long,int%29)
Constructor Details
EncryptedPrivateKeyInfo
public EncryptedPrivateKeyInfo(byte[] encoded) throws IOException
Constructs (i.e., parses) anEncryptedPrivateKeyInfo
from its ASN.1 encoding.
Parameters:
encoded
- the ASN.1 encoding of this object. The contents of the array are copied to protect against subsequent modification.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if theencoded
is null.
[IOException](../../java/io/IOException.html "class in java.io")
- if error occurs when parsing the ASN.1 encoding.EncryptedPrivateKeyInfo
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
- encryption algorithm name. See the Java Security Standard Algorithm Names document for information about standard Cipher algorithm names.
encryptedData
- encrypted data. The contents ofencrypedData
are copied to protect against subsequent modification when constructing this object.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- ifalgName
orencryptedData
is null.
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- ifencryptedData
is empty, i.e. 0-length.
[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")
- if the specified algName is not supported.EncryptedPrivateKeyInfo
Constructs an
EncryptedPrivateKeyInfo
from the encryption algorithm parameters and the encrypted data.
Parameters:
algParams
- the algorithm parameters for the encryption algorithm.algParams.getEncoded()
should return the ASN.1 encoded bytes of theparameters
field of theAlgorithmIdentifer
component of theEncryptedPrivateKeyInfo
type.
encryptedData
- encrypted data. The contents ofencrypedData
are copied to protect against subsequent modification when constructing this object.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- ifalgParams
orencryptedData
is null.
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- ifencryptedData
is empty, i.e. 0-length.
[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")
- if the specified algName of the specifiedalgParams
parameter is not supported.Method Details
getAlgName
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 the Java Security Standard Algorithm Names document for information about standard Cipher algorithm names.
Returns:
the encryption algorithm name.getAlgParameters
Returns the algorithm parameters used by the encryption algorithm.
Returns:
the algorithm parameters.getEncryptedData
public byte[] getEncryptedData()
Returns the encrypted data.
Returns:
the encrypted data. Returns a new array each time this method is called.getKeySpec
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
- the initialized cipher object which will be used for decrypting the encrypted data.
Returns:
the PKCS8EncodedKeySpec object.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- ifcipher
is null.
[InvalidKeySpecException](../../java/security/spec/InvalidKeySpecException.html "class in java.security.spec")
- if the given cipher is inappropriate for the encrypted data or the encrypted data is corrupted and cannot be decrypted.getKeySpec
Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.
Parameters:
decryptKey
- key used for decrypting the encrypted data.
Returns:
the PKCS8EncodedKeySpec object.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- ifdecryptKey
is null.
[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")
- if cannot find appropriate cipher to decrypt the encrypted data.
[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")
- ifdecryptKey
cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec.
Since:
1.5getKeySpec
Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.
Parameters:
decryptKey
- key used for decrypting the encrypted data.
providerName
- the name of provider whose Cipher implementation will be used.
Returns:
the PKCS8EncodedKeySpec object.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- ifdecryptKey
orproviderName
is null.
[NoSuchProviderException](../../java/security/NoSuchProviderException.html "class in java.security")
- if no providerproviderName
is registered.
[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")
- if cannot find appropriate cipher to decrypt the encrypted data.
[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")
- ifdecryptKey
cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec.
Since:
1.5getKeySpec
Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.
Parameters:
decryptKey
- key used for decrypting the encrypted data.
provider
- the name of provider whose Cipher implementation will be used.
Returns:
the PKCS8EncodedKeySpec object.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- ifdecryptKey
orprovider
is null.
[NoSuchAlgorithmException](../../java/security/NoSuchAlgorithmException.html "class in java.security")
- if cannot find appropriate cipher to decrypt the encrypted data inprovider
.
[InvalidKeyException](../../java/security/InvalidKeyException.html "class in java.security")
- ifdecryptKey
cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec.
Since:
1.5getEncoded
public byte[] getEncoded() throws IOException
Returns the ASN.1 encoding of this object.
Returns:
the ASN.1 encoding. Returns a new array each time this method is called.
Throws:
[IOException](../../java/io/IOException.html "class in java.io")
- if error occurs when constructing its ASN.1 encoding.