KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > crypto > EncryptedPrivateKeyInfo


1 /*
2  * @(#)EncryptedPrivateKeyInfo.java 1.13 04/01/14
3  *
4  * Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7   
8 /*
9  * NOTE:
10  * Because of various external restrictions (i.e. US export
11  * regulations, etc.), the actual source code can not be provided
12  * at this time. This file represents the skeleton of the source
13  * file, so that javadocs of the API can be created.
14  */

15
16 package javax.crypto;
17
18 import java.io.*;
19 import java.security.*;
20 import java.security.spec.*;
21
22 import sun.security.x509.AlgorithmId;
23 import sun.security.util.DerValue;
24 import sun.security.util.DerInputStream;
25 import sun.security.util.DerOutputStream;
26
27 /**
28  * This class implements the <code>EncryptedPrivateKeyInfo</code> type
29  * as defined in PKCS #8.
30  * <p>Its ASN.1 definition is as follows:
31  *
32  * <pre>
33  * EncryptedPrivateKeyInfo ::= SEQUENCE {
34  * encryptionAlgorithm AlgorithmIdentifier,
35  * encryptedData OCTET STRING }
36  *
37  * AlgorithmIdentifier ::= SEQUENCE {
38  * algorithm OBJECT IDENTIFIER,
39  * parameters ANY DEFINED BY algorithm OPTIONAL }
40  * </pre>
41  *
42  * @author Valerie Peng
43  *
44  * @version 1.14, 04/01/14
45  *
46  * @see java.security.spec.PKCS8EncodedKeySpec
47  *
48  * @since 1.4
49  */

50 public class EncryptedPrivateKeyInfo
51 {
52
53     /**
54      * Constructs (i.e., parses) an <code>EncryptedPrivateKeyInfo</code> from
55      * its ASN.1 encoding.
56      * @param encoded the ASN.1 encoding of this object. The contents of
57      * the array are copied to protect against subsequent modification.
58      * @exception NullPointerException if the <code>encoded</code> is null.
59      * @exception IOException if error occurs when parsing the ASN.1 encoding.
60      */

61     public EncryptedPrivateKeyInfo(byte[] encoded) throws IOException { }
62
63     /**
64      * Constructs an <code>EncryptedPrivateKeyInfo</code> from the
65      * encryption algorithm name and the encrypted data.
66      *
67      * <p>Note: This constructor will use null as the value of the
68      * algorithm parameters. If the encryption algorithm has
69      * parameters whose value is not null, a different constructor,
70      * e.g. EncryptedPrivateKeyInfo(AlgorithmParameters, byte[]),
71      * should be used.
72      *
73      * @param algName encryption algorithm name. See Appendix A in the
74      * <a HREF="../../../guide/security/jce/JCERefGuide.html#AppA">
75      * Java Cryptography Extension Reference Guide</a>
76      * for information about standard Cipher algorithm names.
77      * @param encryptedData encrypted data. The contents of
78      * <code>encrypedData</code> are copied to protect against subsequent
79      * modification when constructing this object.
80      * @exception NullPointerException if <code>algName</code> or
81      * <code>encryptedData</code> is null.
82      * @exception IllegalArgumentException if <code>encryptedData</code>
83      * is empty, i.e. 0-length.
84      * @exception NoSuchAlgorithmException if the specified algName is
85      * not supported.
86      */

87     public EncryptedPrivateKeyInfo(String algName, byte[] encryptedData)
88         throws NoSuchAlgorithmException
89     { }
90
91     /**
92      * Constructs an <code>EncryptedPrivateKeyInfo</code> from the
93      * encryption algorithm parameters and the encrypted data.
94      *
95      * @param algParams the algorithm parameters for the encryption
96      * algorithm. <code>algParams.getEncoded()</code> should return
97      * the ASN.1 encoded bytes of the <code>parameters</code> field
98      * of the <code>AlgorithmIdentifer</code> component of the
99      * <code>EncryptedPrivateKeyInfo</code> type.
100      * @param encryptedData encrypted data. The contents of
101      * <code>encrypedData</code> are copied to protect against
102      * subsequent modification when constructing this object.
103      * @exception NullPointerException if <code>algParams</code> or
104      * <code>encryptedData</code> is null.
105      * @exception IllegalArgumentException if <code>encryptedData</code>
106      * is empty, i.e. 0-length.
107      * @exception NoSuchAlgorithmException if the specified algName of
108      * the specified <code>algParams</code> parameter is not supported.
109      */

110     public EncryptedPrivateKeyInfo(AlgorithmParameters algParams, byte[]
111         encryptedData) throws NoSuchAlgorithmException
112     { }
113
114     /**
115      * Returns the encryption algorithm.
116      * <p>Note: Standard name is returned instead of the specified one
117      * in the constructor when such mapping is available.
118      * See Appendix A in the
119      * <a HREF="../../../guide/security/jce/JCERefGuide.html#AppA">
120      * Java Cryptography Extension Reference Guide</a>
121      * for information about standard Cipher algorithm names.
122      *
123      * @return the encryption algorithm name.
124      */

125     public String getAlgName() { }
126
127     /**
128      * Returns the algorithm parameters used by the encryption algorithm.
129      * @return the algorithm parameters.
130      */

131     public AlgorithmParameters getAlgParameters() { }
132
133     /**
134      * Returns the encrypted data.
135      * @return the encrypted data. Returns a new array
136      * each time this method is called.
137      */

138     public byte[] getEncryptedData() { }
139
140     /**
141      * Extract the enclosed PKCS8EncodedKeySpec object from the
142      * encrypted data and return it.
143      * <br>Note: In order to successfully retrieve the enclosed
144      * PKCS8EncodedKeySpec object, <code>cipher</code> needs
145      * to be initialized to either Cipher.DECRYPT_MODE or
146      * Cipher.UNWRAP_MODE, with the same key and parameters used
147      * for generating the encrypted data.
148      *
149      * @param cipher the initialized cipher object which will be
150      * used for decrypting the encrypted data.
151      * @return the PKCS8EncodedKeySpec object.
152      * @exception NullPointerException if <code>cipher</code>
153      * is null.
154      * @exception InvalidKeySpecException if the given cipher is
155      * inappropriate for the encrypted data or the encrypted
156      * data is corrupted and cannot be decrypted.
157      */

158     public PKCS8EncodedKeySpec getKeySpec(Cipher cipher)
159         throws InvalidKeySpecException
160     { }
161
162     /**
163      * Extract the enclosed PKCS8EncodedKeySpec object from the
164      * encrypted data and return it.
165      * @param decryptKey key used for decrypting the encrypted data.
166      * @return the PKCS8EncodedKeySpec object.
167      * @exception NullPointerException if <code>decryptKey</code>
168      * is null.
169      * @exception NoSuchAlgorithmException if cannot find appropriate
170      * cipher to decrypt the encrypted data.
171      * @exception InvalidKeyException if <code>decryptKey</code>
172      * cannot be used to decrypt the encrypted data or the decryption
173      * result is not a valid PKCS8KeySpec.
174      */

175     public PKCS8EncodedKeySpec getKeySpec(Key decryptKey)
176         throws NoSuchAlgorithmException, InvalidKeyException
177     { }
178
179     /**
180      * Extract the enclosed PKCS8EncodedKeySpec object from the
181      * encrypted data and return it.
182      * @param decryptKey key used for decrypting the encrypted data.
183      * @param providerName the name of provider whose Cipher
184      * implementation will be used.
185      * @return the PKCS8EncodedKeySpec object.
186      * @exception NullPointerException if <code>decryptKey</code>
187      * or <code>providerName</code> is null.
188      * @exception NoSuchProviderException if no provider
189      * <code>providerName</code> is registered.
190      * @exception NoSuchAlgorithmException if cannot find appropriate
191      * cipher to decrypt the encrypted data.
192      * @exception InvalidKeyException if <code>decryptKey</code>
193      * cannot be used to decrypt the encrypted data or the decryption
194      * result is not a valid PKCS8KeySpec.
195      */

196     public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, String providerName)
197         throws NoSuchProviderException, NoSuchAlgorithmException,
198         InvalidKeyException
199     { }
200
201     /**
202      * Extract the enclosed PKCS8EncodedKeySpec object from the
203      * encrypted data and return it.
204      * @param decryptKey key used for decrypting the encrypted data.
205      * @param provider the name of provider whose Cipher implementation
206      * will be used.
207      * @return the PKCS8EncodedKeySpec object.
208      * @exception NullPointerException if <code>decryptKey</code>
209      * or <code>provider</code> is null.
210      * @exception NoSuchAlgorithmException if cannot find appropriate
211      * cipher to decrypt the encrypted data in <code>provider</code>.
212      * @exception InvalidKeyException if <code>decryptKey</code>
213      * cannot be used to decrypt the encrypted data or the decryption
214      * result is not a valid PKCS8KeySpec.
215      */

216     public PKCS8EncodedKeySpec getKeySpec(Key decryptKey, Provider provider)
217         throws NoSuchAlgorithmException, InvalidKeyException
218     { }
219
220     /**
221      * Returns the ASN.1 encoding of this object.
222      * @return the ASN.1 encoding. Returns a new array
223      * each time this method is called.
224      * @exception IOException if error occurs when constructing its
225      * ASN.1 encoding.
226      */

227     public byte[] getEncoded() throws IOException { }
228 }
229
Popular Tags