author | naoto |
Tue, 15 Oct 2019 09:25:59 -0700 | |
changeset 58603 | 2312d1a04c49 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45118
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
35302
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.security.spec; |
|
27 |
||
28 |
/** |
|
29 |
* This class represents the ASN.1 encoding of a private key, |
|
18552
005e115dc6ee
8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents:
5506
diff
changeset
|
30 |
* encoded according to the ASN.1 type {@code PrivateKeyInfo}. |
005e115dc6ee
8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents:
5506
diff
changeset
|
31 |
* The {@code PrivateKeyInfo} syntax is defined in the PKCS#8 standard |
2 | 32 |
* as follows: |
33 |
* |
|
34 |
* <pre> |
|
35 |
* PrivateKeyInfo ::= SEQUENCE { |
|
36 |
* version Version, |
|
37 |
* privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, |
|
38 |
* privateKey PrivateKey, |
|
39 |
* attributes [0] IMPLICIT Attributes OPTIONAL } |
|
40 |
* |
|
41 |
* Version ::= INTEGER |
|
42 |
* |
|
43 |
* PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier |
|
44 |
* |
|
45 |
* PrivateKey ::= OCTET STRING |
|
46 |
* |
|
47 |
* Attributes ::= SET OF Attribute |
|
48 |
* </pre> |
|
49 |
* |
|
50 |
* @author Jan Luehe |
|
51 |
* |
|
52 |
* |
|
53 |
* @see java.security.Key |
|
54 |
* @see java.security.KeyFactory |
|
55 |
* @see KeySpec |
|
56 |
* @see EncodedKeySpec |
|
57 |
* @see X509EncodedKeySpec |
|
58 |
* |
|
59 |
* @since 1.2 |
|
60 |
*/ |
|
61 |
||
62 |
public class PKCS8EncodedKeySpec extends EncodedKeySpec { |
|
63 |
||
64 |
/** |
|
26716
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
65 |
* Creates a new {@code PKCS8EncodedKeySpec} with the given encoded key. |
2 | 66 |
* |
67 |
* @param encodedKey the key, which is assumed to be |
|
68 |
* encoded according to the PKCS #8 standard. The contents of |
|
69 |
* the array are copied to protect against subsequent modification. |
|
26716
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
70 |
* @throws NullPointerException if {@code encodedKey} |
2 | 71 |
* is null. |
72 |
*/ |
|
73 |
public PKCS8EncodedKeySpec(byte[] encodedKey) { |
|
74 |
super(encodedKey); |
|
75 |
} |
|
76 |
||
77 |
/** |
|
26716
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
78 |
* Creates a new {@code PKCS8EncodedKeySpec} with the given encoded key and |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
79 |
* algorithm. This constructor is useful when subsequent callers of |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
80 |
* the {@code PKCS8EncodedKeySpec} object might not know the |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
81 |
* algorithm of the private key. |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
82 |
* |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
83 |
* @param encodedKey the key, which is assumed to be |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
84 |
* encoded according to the PKCS #8 standard. The contents of |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
85 |
* the array are copied to protect against subsequent modification. |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
86 |
* @param algorithm the algorithm name of the encoded private key |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
87 |
* See the KeyFactory section in the <a href= |
45118
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
35302
diff
changeset
|
88 |
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms"> |
e4258d800b54
8178278: Move Standard Algorithm Names document to specs directory
ihse
parents:
35302
diff
changeset
|
89 |
* Java Security Standard Algorithm Names Specification</a> |
26716
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
90 |
* for information about standard algorithm names. |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
91 |
* @throws NullPointerException if {@code encodedKey} |
29379 | 92 |
* or {@code algorithm} is null. |
26716
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
93 |
* @throws IllegalArgumentException if {@code algorithm} is |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
94 |
* the empty string {@code ""} |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
29379
diff
changeset
|
95 |
* @since 9 |
26716
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
96 |
*/ |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
97 |
public PKCS8EncodedKeySpec(byte[] encodedKey, String algorithm) { |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
98 |
super(encodedKey, algorithm); |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
99 |
} |
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
100 |
|
189794fe8ba2
8047223: Add algorithm parameter to EncodedKeySpec class and its two subclasses
juh
parents:
25859
diff
changeset
|
101 |
/** |
2 | 102 |
* Returns the key bytes, encoded according to the PKCS #8 standard. |
103 |
* |
|
104 |
* @return the PKCS #8 encoding of the key. Returns a new array |
|
105 |
* each time this method is called. |
|
106 |
*/ |
|
107 |
public byte[] getEncoded() { |
|
108 |
return super.getEncoded(); |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* Returns the name of the encoding format associated with this |
|
113 |
* key specification. |
|
114 |
* |
|
18552
005e115dc6ee
8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents:
5506
diff
changeset
|
115 |
* @return the string {@code "PKCS#8"}. |
2 | 116 |
*/ |
117 |
public final String getFormat() { |
|
118 |
return "PKCS#8"; |
|
119 |
} |
|
120 |
} |