Class EncryptedPrivateKeyInfo
- All Implemented Interfaces:
BinaryEncodablePREVIEW
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
ConstructorsConstructorDescriptionEncryptedPrivateKeyInfo(byte[] encoded) Constructs anEncryptedPrivateKeyInfofrom a given encrypted PKCS#8 ASN.1 encoding.EncryptedPrivateKeyInfo(String algName, byte[] encryptedData) Constructs anEncryptedPrivateKeyInfofrom the encryption algorithm name and the encrypted data.EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData) Constructs anEncryptedPrivateKeyInfofrom the encryption algorithm parameters and the encrypted data. -
Method Summary
Modifier and TypeMethodDescriptionstatic EncryptedPrivateKeyInfoencrypt(BinaryEncodablePREVIEW be, char[] password) Preview.Creates anEncryptedPrivateKeyInfoby encrypting the specifiedBinaryEncodable.static EncryptedPrivateKeyInfoencrypt(BinaryEncodablePREVIEW be, char[] password, String algorithm, AlgorithmParameterSpec params, Provider provider) Preview.Creates anEncryptedPrivateKeyInfoby encrypting the specifiedBinaryEncodable.static EncryptedPrivateKeyInfoencrypt(BinaryEncodablePREVIEW be, Key encryptKey, String algorithm, AlgorithmParameterSpec params, Provider provider, SecureRandom random) Preview.Creates anEncryptedPrivateKeyInfoby encrypting the specifiedBinaryEncodable.Returns the encryption algorithm.Returns the algorithm parameters used by the encryption algorithm.byte[]Returns the ASN.1 encoding of this object.byte[]Returns the encrypted data.getKey(char[] password) Preview.Extracts and returns the enclosedPrivateKeyusing the specified password.Preview.Extracts and returns the enclosedPrivateKeyusing the specified decryption key.getKeyPair(char[] password) Preview.Extracts and returns the enclosedKeyPairusing the specified password.getKeyPair(Key decryptKey) Preview.Extracts and returns the enclosedKeyPairusing the specified decryption key.getKeySpec(Key decryptKey) Extracts the enclosed PKCS8EncodedKeySpec object from the encrypted data and returns it.getKeySpec(Key decryptKey, String providerName) Extracts the enclosed PKCS8EncodedKeySpec object from the encrypted data and returns it.getKeySpec(Key decryptKey, Provider provider) Extracts the enclosed PKCS8EncodedKeySpec object from the encrypted data and returns it.getKeySpec(Cipher cipher) Extracts the enclosed PKCS8EncodedKeySpec object from the encrypted data and returns it.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
EncryptedPrivateKeyInfo
Constructs anEncryptedPrivateKeyInfofrom a given encrypted PKCS#8 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- ifencodedisnull.IOException- if error occurs when parsing the ASN.1 encoding.
-
EncryptedPrivateKeyInfo
public EncryptedPrivateKeyInfo(String algName, byte[] encryptedData) throws NoSuchAlgorithmException Constructs anEncryptedPrivateKeyInfofrom the encryption algorithm name and the encrypted data.Note: This constructor will use
nullas the value of the algorithm parameters. If the encryption algorithm has parameters whose value is notnull, 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 ofencryptedDataare copied to protect against subsequent modification when constructing this object.- Throws:
NullPointerException- ifalgNameorencryptedDataisnull.IllegalArgumentException- ifencryptedDatais empty, i.e. 0-length.NoSuchAlgorithmException- if the specified algName is not supported.- External Specifications
-
EncryptedPrivateKeyInfo
public EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData) throws NoSuchAlgorithmException Constructs anEncryptedPrivateKeyInfofrom 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 theparametersfield of theAlgorithmIdentifiercomponent of theEncryptedPrivateKeyInfotype.encryptedData- encrypted data. The contents ofencryptedDataare copied to protect against subsequent modification when constructing this object.- Throws:
NullPointerException- ifalgParamsorencryptedDataisnull.IllegalArgumentException- ifencryptedDatais empty, i.e. 0-length.NoSuchAlgorithmException- if the specified algName of the specifiedalgParamsparameter is not supported.
-
-
Method Details
-
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.
- External Specifications
-
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
Extracts the enclosed PKCS8EncodedKeySpec object from the encrypted data and returns it.
Note: In order to successfully retrieve the enclosed PKCS8EncodedKeySpec object,cipherneeds 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 initializedCipherobject which will be used for decrypting the encrypted data.- Returns:
- the PKCS8EncodedKeySpec object
- Throws:
NullPointerException- ifcipherisnull.InvalidKeySpecException- if the given cipher is inappropriate for the encrypted data or the encrypted data is corrupted and cannot be decrypted.
-
encrypt
public static EncryptedPrivateKeyInfo encrypt(BinaryEncodablePREVIEW be, char[] password, String algorithm, AlgorithmParameterSpec params, Provider provider) encryptis a preview API of the Java platform.Programs can only useencryptwhen preview features are enabled.Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.Creates anEncryptedPrivateKeyInfoby encrypting the specifiedBinaryEncodable. A valid password-based encryption (PBE) algorithm and password must be specified.The format of the PBE algorithm string is described in the Cipher Algorithms section of the Java Security Standard Algorithm Names Specification.
- Parameters:
be- theBinaryEncodableto encrypt. Supported types includePrivateKey,KeyPair, andPKCS8EncodedKeySpec.password- the password used for PBE encryption. This array is cloned before use.algorithm- the PBE encryption algorithmparams- theAlgorithmParameterSpecused for encryption. Ifnull, the provider’s default parameters are applied.provider- theProviderforSecretKeyFactoryandCipheroperations. Ifnull, the default provider list is used.- Returns:
- an
EncryptedPrivateKeyInfo - Throws:
NullPointerException- ifbe,password, oralgorithmisnullIllegalArgumentException- ifbeis an unsupportedBinaryEncodableor has no encodingCryptoExceptionPREVIEW- if an error occurs while generating the PBE key, ifalgorithmorparamsare not supported by any provider, or if an error occurs during encryption- Since:
- 27
-
encrypt
encryptis a preview API of the Java platform.Programs can only useencryptwhen preview features are enabled.Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.Creates anEncryptedPrivateKeyInfoby encrypting the specifiedBinaryEncodable. A valid password must be specified. A default password-based encryption (PBE) algorithm and provider are used.- Implementation Note:
- The
jdk.epkcs8.defaultAlgorithmsecurity property defines the default encryption algorithm. TheAlgorithmParameterSpecdefaults are determined by the provider. - Parameters:
be- theBinaryEncodableto encrypt. Supported types includePrivateKey,KeyPair, andPKCS8EncodedKeySpec.password- the password used for PBE encryption. This array is cloned before use.- Returns:
- an
EncryptedPrivateKeyInfo - Throws:
NullPointerException- ifbeorpasswordisnullIllegalArgumentException- ifbeis an unsupportedBinaryEncodableor has no encodingCryptoExceptionPREVIEW- if an error occurs while generating the PBE key, if the default algorithm is misconfigured, or if an error occurs during encryption- Since:
- 27
-
encrypt
public static EncryptedPrivateKeyInfo encrypt(BinaryEncodablePREVIEW be, Key encryptKey, String algorithm, AlgorithmParameterSpec params, Provider provider, SecureRandom random) encryptis a preview API of the Java platform.Programs can only useencryptwhen preview features are enabled.Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.Creates anEncryptedPrivateKeyInfoby encrypting the specifiedBinaryEncodable. A valid encryption algorithm andKeymust be specified.The format of the algorithm string is described in the Cipher Algorithms section of the Java Security Standard Algorithm Names Specification.
- Parameters:
be- theBinaryEncodableto encrypt. Supported types includePrivateKey,KeyPair, andPKCS8EncodedKeySpec.encryptKey- the key used to encrypt the encodingalgorithm- the encryption algorithm, such as a password-based encryption (PBE) algorithmparams- theAlgorithmParameterSpecused for encryption. Ifnull, the provider’s default parameters are applied.provider- theProviderforCipheroperations. Ifnull, the default provider list is used.random- theSecureRandominstance used during encryption. Ifnull, the default is used.- Returns:
- an
EncryptedPrivateKeyInfo - Throws:
NullPointerException- ifbe,encryptKey, oralgorithmisnullIllegalArgumentException- ifbeis an unsupportedBinaryEncodableor has no encodingCryptoExceptionPREVIEW- ifencryptKeyis invalid, ifalgorithmorparamsare not supported by any provider, or if an error occurs during encryption- Since:
- 27
-
getKey
getKeyis a preview API of the Java platform.Programs can only usegetKeywhen preview features are enabled.Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.Extracts and returns the enclosedPrivateKeyusing the specified password.- Parameters:
password- the password used for PBE decryption. The array is cloned before use.- Returns:
- the decrypted
PrivateKey - Throws:
NullPointerException- ifpasswordisnullNoSuchAlgorithmException- if the decryption algorithm is unsupportedInvalidKeyException- if an error occurs during parsing, decryption, or key generation- Since:
- 25
-
getKey
getKeyis a preview API of the Java platform.Programs can only usegetKeywhen preview features are enabled.Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.Extracts and returns the enclosedPrivateKeyusing the specified decryption key.- Parameters:
decryptKey- the decryption key; must not benull- Returns:
- the decrypted
PrivateKey - Throws:
NullPointerException- ifdecryptKeyisnullNoSuchAlgorithmException- if the decryption algorithm is unsupportedInvalidKeyException- if an error occurs during parsing, decryption, or key generation- Since:
- 27
-
getKeyPair
getKeyPairis a preview API of the Java platform.Programs can only usegetKeyPairwhen preview features are enabled.Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.Extracts and returns the enclosedKeyPairusing the specified password. If the encoded data does not contain both a public and private key, anInvalidKeyExceptionis thrown.- Parameters:
password- the password used for PBE decryption. The array is cloned before use.- Returns:
- a decrypted
KeyPair - Throws:
NullPointerException- ifpasswordisnullNoSuchAlgorithmException- if the decryption algorithm is unsupportedInvalidKeyException- if the encoded data lacks a public key, or if an error occurs during parsing, decryption, or key generation- Since:
- 26
-
getKeyPair
getKeyPairis a preview API of the Java platform.Programs can only usegetKeyPairwhen preview features are enabled.Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.Extracts and returns the enclosedKeyPairusing the specified decryption key. If the encoded data does not contain both a public and private key, anInvalidKeyExceptionis thrown.- Parameters:
decryptKey- the decryption key; must not benull- Returns:
- a decrypted
KeyPair - Throws:
NullPointerException- ifdecryptKeyisnullNoSuchAlgorithmException- if the decryption algorithm is unsupportedInvalidKeyException- if the encoded data lacks a public key, or if an error occurs during parsing, decryption, or key generation- Since:
- 27
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey) throws NoSuchAlgorithmException, InvalidKeyException Extracts the enclosed PKCS8EncodedKeySpec object from the encrypted data and returns it.- Parameters:
decryptKey- key used for decrypting the encrypted data.- Returns:
- the PKCS8EncodedKeySpec object with a specified algorithm
- Throws:
NullPointerException- ifdecryptKeyisnull.NoSuchAlgorithmException- if cannot find appropriate cipher to decrypt the encrypted data.InvalidKeyException- ifdecryptKeycannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8EncodedKeySpec.- Since:
- 1.5
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, String providerName) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException Extracts the enclosed PKCS8EncodedKeySpec object from the encrypted data and returns 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 with a specified algorithm
- Throws:
NullPointerException- ifdecryptKeyorproviderNameisnull.NoSuchProviderException- if no providerproviderNameis registered.NoSuchAlgorithmException- if cannot find appropriate cipher to decrypt the encrypted data.InvalidKeyException- ifdecryptKeycannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8EncodedKeySpec.- Since:
- 1.5
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, Provider provider) throws NoSuchAlgorithmException, InvalidKeyException Extracts the enclosed PKCS8EncodedKeySpec object from the encrypted data and returns it.- Parameters:
decryptKey- key used for decrypting the encrypted data.provider- the provider whose cipher implementation will be used.- Returns:
- the PKCS8EncodedKeySpec object with a specified algorithm
- Throws:
NullPointerException- ifdecryptKeyorproviderisnull.NoSuchAlgorithmException- if cannot find appropriate cipher to decrypt the encrypted data inprovider.InvalidKeyException- ifdecryptKeycannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8EncodedKeySpec.- Since:
- 1.5
-
getEncoded
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- if error occurs when constructing its ASN.1 encoding.
-