1PKCS8(1) OpenSSL PKCS8(1)
2
3
4
6 pkcs8 - PKCS#8 format private key conversion tool
7
9 openssl pkcs8 [-topk8] [-inform PEM⎪DER] [-outform PEM⎪DER] [-in file‐
10 name] [-passin arg] [-out filename] [-passout arg] [-noiter] [-nocrypt]
11 [-nooct] [-embed] [-nsdb] [-v2 alg] [-v1 alg] [-engine id]
12
14 The pkcs8 command processes private keys in PKCS#8 format. It can han‐
15 dle both unencrypted PKCS#8 PrivateKeyInfo format and EncryptedPri‐
16 vateKeyInfo format with a variety of PKCS#5 (v1.5 and v2.0) and PKCS#12
17 algorithms.
18
20 -topk8
21 Normally a PKCS#8 private key is expected on input and a tradi‐
22 tional format private key will be written. With the -topk8 option
23 the situation is reversed: it reads a traditional format private
24 key and writes a PKCS#8 format key.
25
26 -inform DER⎪PEM
27 This specifies the input format. If a PKCS#8 format key is expected
28 on input then either a DER or PEM encoded version of a PKCS#8 key
29 will be expected. Otherwise the DER or PEM format of the tradi‐
30 tional format private key is used.
31
32 -outform DER⎪PEM
33 This specifies the output format, the options have the same meaning
34 as the -inform option.
35
36 -in filename
37 This specifies the input filename to read a key from or standard
38 input if this option is not specified. If the key is encrypted a
39 pass phrase will be prompted for.
40
41 -passin arg
42 the input file password source. For more information about the for‐
43 mat of arg see the PASS PHRASE ARGUMENTS section in openssl(1).
44
45 -out filename
46 This specifies the output filename to write a key to or standard
47 output by default. If any encryption options are set then a pass
48 phrase will be prompted for. The output filename should not be the
49 same as the input filename.
50
51 -passout arg
52 the output file password source. For more information about the
53 format of arg see the PASS PHRASE ARGUMENTS section in openssl(1).
54
55 -nocrypt
56 PKCS#8 keys generated or input are normally PKCS#8 EncryptedPri‐
57 vateKeyInfo structures using an appropriate password based encryp‐
58 tion algorithm. With this option an unencrypted PrivateKeyInfo
59 structure is expected or output. This option does not encrypt pri‐
60 vate keys at all and should only be used when absolutely necessary.
61 Certain software such as some versions of Java code signing soft‐
62 ware used unencrypted private keys.
63
64 -nooct
65 This option generates RSA private keys in a broken format that some
66 software uses. Specifically the private key should be enclosed in a
67 OCTET STRING but some software just includes the structure itself
68 without the surrounding OCTET STRING.
69
70 -embed
71 This option generates DSA keys in a broken format. The DSA parame‐
72 ters are embedded inside the PrivateKey structure. In this form the
73 OCTET STRING contains an ASN1 SEQUENCE consisting of two struc‐
74 tures: a SEQUENCE containing the parameters and an ASN1 INTEGER
75 containing the private key.
76
77 -nsdb
78 This option generates DSA keys in a broken format compatible with
79 Netscape private key databases. The PrivateKey contains a SEQUENCE
80 consisting of the public and private keys respectively.
81
82 -v2 alg
83 This option enables the use of PKCS#5 v2.0 algorithms. Normally
84 PKCS#8 private keys are encrypted with the password based encryp‐
85 tion algorithm called pbeWithMD5AndDES-CBC this uses 56 bit DES
86 encryption but it was the strongest encryption algorithm supported
87 in PKCS#5 v1.5. Using the -v2 option PKCS#5 v2.0 algorithms are
88 used which can use any encryption algorithm such as 168 bit triple
89 DES or 128 bit RC2 however not many implementations support PKCS#5
90 v2.0 yet. If you are just using private keys with OpenSSL then this
91 doesn't matter.
92
93 The alg argument is the encryption algorithm to use, valid values
94 include des, des3 and rc2. It is recommended that des3 is used.
95
96 -v1 alg
97 This option specifies a PKCS#5 v1.5 or PKCS#12 algorithm to use. A
98 complete list of possible algorithms is included below.
99
100 -engine id
101 specifying an engine (by it's unique id string) will cause req to
102 attempt to obtain a functional reference to the specified engine,
103 thus initialising it if needed. The engine will then be set as the
104 default for all available algorithms.
105
107 The encrypted form of a PEM encode PKCS#8 files uses the following
108 headers and footers:
109
110 -----BEGIN ENCRYPTED PRIVATE KEY-----
111 -----END ENCRYPTED PRIVATE KEY-----
112
113 The unencrypted form uses:
114
115 -----BEGIN PRIVATE KEY-----
116 -----END PRIVATE KEY-----
117
118 Private keys encrypted using PKCS#5 v2.0 algorithms and high iteration
119 counts are more secure that those encrypted using the traditional
120 SSLeay compatible formats. So if additional security is considered
121 important the keys should be converted.
122
123 The default encryption is only 56 bits because this is the encryption
124 that most current implementations of PKCS#8 will support.
125
126 Some software may use PKCS#12 password based encryption algorithms with
127 PKCS#8 format private keys: these are handled automatically but there
128 is no option to produce them.
129
130 It is possible to write out DER encoded encrypted private keys in
131 PKCS#8 format because the encryption details are included at an ASN1
132 level whereas the traditional format includes them at a PEM level.
133
135 Various algorithms can be used with the -v1 command line option,
136 including PKCS#5 v1.5 and PKCS#12. These are described in more detail
137 below.
138
139 PBE-MD2-DES PBE-MD5-DES
140 These algorithms were included in the original PKCS#5 v1.5 specifi‐
141 cation. They only offer 56 bits of protection since they both use
142 DES.
143
144 PBE-SHA1-RC2-64 PBE-MD2-RC2-64 PBE-MD5-RC2-64 PBE-SHA1-DES
145 These algorithms are not mentioned in the original PKCS#5 v1.5
146 specification but they use the same key derivation algorithm and
147 are supported by some software. They are mentioned in PKCS#5 v2.0.
148 They use either 64 bit RC2 or 56 bit DES.
149
150 PBE-SHA1-RC4-128 PBE-SHA1-RC4-40 PBE-SHA1-3DES PBE-SHA1-2DES
151 PBE-SHA1-RC2-128 PBE-SHA1-RC2-40
152 These algorithms use the PKCS#12 password based encryption algo‐
153 rithm and allow strong encryption algorithms like triple DES or 128
154 bit RC2 to be used.
155
157 Convert a private from traditional to PKCS#5 v2.0 format using triple
158 DES:
159
160 openssl pkcs8 -in key.pem -topk8 -v2 des3 -out enckey.pem
161
162 Convert a private key to PKCS#8 using a PKCS#5 1.5 compatible algorithm
163 (DES):
164
165 openssl pkcs8 -in key.pem -topk8 -out enckey.pem
166
167 Convert a private key to PKCS#8 using a PKCS#12 compatible algorithm
168 (3DES):
169
170 openssl pkcs8 -in key.pem -topk8 -out enckey.pem -v1 PBE-SHA1-3DES
171
172 Read a DER unencrypted PKCS#8 format private key:
173
174 openssl pkcs8 -inform DER -nocrypt -in key.der -out key.pem
175
176 Convert a private key from any PKCS#8 format to traditional format:
177
178 openssl pkcs8 -in pk8.pem -out key.pem
179
181 Test vectors from this PKCS#5 v2.0 implementation were posted to the
182 pkcs-tng mailing list using triple DES, DES and RC2 with high iteration
183 counts, several people confirmed that they could decrypt the private
184 keys produced and Therefore it can be assumed that the PKCS#5 v2.0
185 implementation is reasonably accurate at least as far as these algo‐
186 rithms are concerned.
187
188 The format of PKCS#8 DSA (and other) private keys is not well docu‐
189 mented: it is hidden away in PKCS#11 v2.01, section 11.9. OpenSSL's
190 default DSA PKCS#8 private key format complies with this standard.
191
193 There should be an option that prints out the encryption algorithm in
194 use and other details such as the iteration count.
195
196 PKCS#8 using triple DES and PKCS#5 v2.0 should be the default private
197 key format for OpenSSL: for compatibility several of the utilities use
198 the old format at present.
199
201 dsa(1), rsa(1), genrsa(1), gendsa(1)
202
203
204
2050.9.8b 2003-01-30 PKCS8(1)