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