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
10 filename] [-passin arg] [-out filename] [-passout arg] [-noiter]
11 [-nocrypt] [-nooct] [-embed] [-nsdb] [-v2 alg] [-v1 alg] [-engine id]
12
14 The pkcs8 command processes private keys in PKCS#8 format. It can
15 handle both unencrypted PKCS#8 PrivateKeyInfo format and
16 EncryptedPrivateKeyInfo format with a variety of PKCS#5 (v1.5 and v2.0)
17 and PKCS#12 algorithms.
18
20 -topk8
21 Normally a PKCS#8 private key is expected on input and a
22 traditional format private key will be written. With the -topk8
23 option the situation is reversed: it reads a traditional format
24 private 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
30 traditional 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
43 format 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
57 EncryptedPrivateKeyInfo structures using an appropriate password
58 based encryption algorithm. With this option an unencrypted
59 PrivateKeyInfo structure is expected or output. This option does
60 not encrypt private keys at all and should only be used when
61 absolutely necessary. Certain software such as some versions of
62 Java code signing software 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
72 parameters are embedded inside the PrivateKey structure. In this
73 form the OCTET STRING contains an ASN1 SEQUENCE consisting of two
74 structures: a SEQUENCE containing the parameters and an ASN1
75 INTEGER 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
85 encryption algorithm called pbeWithMD5AndDES-CBC this uses 56 bit
86 DES encryption but it was the strongest encryption algorithm
87 supported in PKCS#5 v1.5. Using the -v2 option PKCS#5 v2.0
88 algorithms are used which can use any encryption algorithm such as
89 168 bit triple DES or 128 bit RC2 however not many implementations
90 support PKCS#5 v2.0 yet. If you are just using private keys with
91 OpenSSL then this 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 its unique id string) will cause pkcs8 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
141 specification. They only offer 56 bits of protection since they
142 both use 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
153 algorithm and allow strong encryption algorithms like triple DES or
154 128 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
186 algorithms are concerned.
187
188 The format of PKCS#8 DSA (and other) private keys is not well
189 documented: 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
2051.0.0e 2009-04-10 PKCS8(1)