- java.lang.Object
-
- javax.crypto.EncryptedPrivateKeyInfo
-
public class EncryptedPrivateKeyInfo extends Object
This class implements theEncryptedPrivateKeyInfo
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
Constructors Constructor and Description EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData)
Constructs anEncryptedPrivateKeyInfo
from the encryption algorithm parameters and the encrypted data.EncryptedPrivateKeyInfo(byte[] encoded)
Constructs (i.e., parses) anEncryptedPrivateKeyInfo
from its ASN.1 encoding.EncryptedPrivateKeyInfo(String algName, byte[] encryptedData)
Constructs anEncryptedPrivateKeyInfo
from the encryption algorithm name and the encrypted data.
-
Method Summary
Methods Modifier and Type Method and 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(Cipher cipher)
Extract the enclosed PKCS8EncodedKeySpec object from the encrypted data and return it.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.
-
-
-
Constructor Detail
-
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
- if theencoded
is null.IOException
- if error occurs when parsing the ASN.1 encoding.
-
EncryptedPrivateKeyInfo
public EncryptedPrivateKeyInfo(String algName, byte[] encryptedData) throws NoSuchAlgorithmException
Constructs anEncryptedPrivateKeyInfo
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 Appendix A in the Java Cryptography Architecture Reference Guide 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
- ifalgName
orencryptedData
is null.IllegalArgumentException
- ifencryptedData
is empty, i.e. 0-length.NoSuchAlgorithmException
- if the specified algName is not supported.
-
EncryptedPrivateKeyInfo
public EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[] encryptedData) throws NoSuchAlgorithmException
Constructs anEncryptedPrivateKeyInfo
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
- ifalgParams
orencryptedData
is null.IllegalArgumentException
- ifencryptedData
is empty, i.e. 0-length.NoSuchAlgorithmException
- if the specified algName of the specifiedalgParams
parameter is not supported.
-
-
Method Detail
-
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 Appendix A in the Java Cryptography Architecture Reference Guide for information about standard Cipher algorithm names.
- Returns:
- the encryption algorithm name.
-
getAlgParameters
public AlgorithmParameters 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
public PKCS8EncodedKeySpec getKeySpec(Cipher cipher) throws InvalidKeySpecException
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
- ifcipher
is null.InvalidKeySpecException
- if the given cipher is inappropriate for the encrypted data or the encrypted data is corrupted and cannot be decrypted.
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey) throws NoSuchAlgorithmException, InvalidKeyException
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
- ifdecryptKey
is null.NoSuchAlgorithmException
- if cannot find appropriate cipher to decrypt the encrypted data.InvalidKeyException
- ifdecryptKey
cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec.- Since:
- 1.5
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, String providerName) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException
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
- ifdecryptKey
orproviderName
is null.NoSuchProviderException
- if no providerproviderName
is registered.NoSuchAlgorithmException
- if cannot find appropriate cipher to decrypt the encrypted data.InvalidKeyException
- ifdecryptKey
cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec.- Since:
- 1.5
-
getKeySpec
public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, Provider provider) throws NoSuchAlgorithmException, InvalidKeyException
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
- ifdecryptKey
orprovider
is null.NoSuchAlgorithmException
- if cannot find appropriate cipher to decrypt the encrypted data inprovider
.InvalidKeyException
- ifdecryptKey
cannot be used to decrypt the encrypted data or the decryption result is not a valid PKCS8KeySpec.- Since:
- 1.5
-
getEncoded
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
- if error occurs when constructing its ASN.1 encoding.
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/11/2024 21:30:16 Cette version de la page est en cache (à la date du 21/11/2024 21:30:16) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 30/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/crypto/encryptedprivatekeyinfo.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.