openssl-pkcs12.pod.in revision 1.1 1 =pod
2 {- OpenSSL::safe::output_do_not_edit_headers(); -}
3
4 =head1 NAME
5
6 openssl-pkcs12 - PKCS#12 file command
7
8 =head1 SYNOPSIS
9
10 =for openssl duplicate options
11
12 B<openssl> B<pkcs12>
13 [B<-help>]
14 [B<-passin> I<arg>]
15 [B<-passout> I<arg>]
16 [B<-password> I<arg>]
17 [B<-twopass>]
18 [B<-in> I<filename>|I<uri>]
19 [B<-out> I<filename>]
20 [B<-nokeys>]
21 [B<-nocerts>]
22 [B<-noout>]
23 [B<-legacy>]
24 {- $OpenSSL::safe::opt_engine_synopsis -}{- $OpenSSL::safe::opt_provider_synopsis -}
25 {- $OpenSSL::safe::opt_r_synopsis -}
26
27 PKCS#12 input (parsing) options:
28 [B<-info>]
29 [B<-nomacver>]
30 [B<-clcerts>]
31 [B<-cacerts>]
32
33 [B<-aes128>]
34 [B<-aes192>]
35 [B<-aes256>]
36 [B<-aria128>]
37 [B<-aria192>]
38 [B<-aria256>]
39 [B<-camellia128>]
40 [B<-camellia192>]
41 [B<-camellia256>]
42 [B<-des>]
43 [B<-des3>]
44 [B<-idea>]
45 [B<-noenc>]
46 [B<-nodes>]
47
48 PKCS#12 output (export) options:
49
50 [B<-export>]
51 [B<-inkey> I<filename>|I<uri>]
52 [B<-certfile> I<filename>]
53 [B<-passcerts> I<arg>]
54 [B<-chain>]
55 [B<-untrusted> I<filename>]
56 {- $OpenSSL::safe::opt_trust_synopsis -}
57 [B<-name> I<name>]
58 [B<-caname> I<name>]
59 [B<-CSP> I<name>]
60 [B<-LMK>]
61 [B<-keyex>]
62 [B<-keysig>]
63 [B<-keypbe> I<cipher>]
64 [B<-certpbe> I<cipher>]
65 [B<-descert>]
66 [B<-macalg> I<digest>]
67 [B<-pbmac1_pbkdf2>]
68 [B<-pbmac1_pbkdf2_md> I<digest>]
69 [B<-iter> I<count>]
70 [B<-noiter>]
71 [B<-nomaciter>]
72 [B<-maciter>]
73 [B<-macsaltlen>]
74 [B<-nomac>]
75 [B<-jdktrust> I<usage>]
76
77 =head1 DESCRIPTION
78
79 This command allows PKCS#12 files (sometimes referred to as
80 PFX files) to be created and parsed. PKCS#12 files are used by several
81 programs including Netscape, MSIE and MS Outlook.
82
83 =head1 OPTIONS
84
85 There are a lot of options the meaning of some depends of whether a PKCS#12 file
86 is being created or parsed. By default a PKCS#12 file is parsed.
87 A PKCS#12 file can be created by using the B<-export> option (see below).
88 The PKCS#12 export encryption and MAC options such as B<-certpbe> and B<-iter>
89 and many further options such as B<-chain> are relevant only with B<-export>.
90 Conversely, the options regarding encryption of private keys when outputting
91 PKCS#12 input are relevant only when the B<-export> option is not given.
92
93 The default encryption algorithm is AES-256-CBC with PBKDF2 for key derivation.
94
95 When encountering problems loading legacy PKCS#12 files that involve,
96 for example, RC2-40-CBC,
97 try using the B<-legacy> option and, if needed, the B<-provider-path> option.
98
99 =over 4
100
101 =item B<-help>
102
103 Print out a usage message.
104
105 =item B<-passin> I<arg>
106
107 The password source for the input, and for encrypting any private keys that
108 are output.
109 For more information about the format of B<arg>
110 see L<openssl-passphrase-options(1)>.
111
112 =item B<-passout> I<arg>
113
114 The password source for output files.
115
116 =item B<-password> I<arg>
117
118 With B<-export>, B<-password> is equivalent to B<-passout>,
119 otherwise it is equivalent to B<-passin>.
120
121 =item B<-twopass>
122
123 Prompt for separate integrity and encryption passwords: most software
124 always assumes these are the same so this option will render such
125 PKCS#12 files unreadable. Cannot be used in combination with the options
126 B<-password>, B<-passin> if importing from PKCS#12, or B<-passout> if exporting.
127
128 =item B<-nokeys>
129
130 No private keys will be output.
131
132 =item B<-nocerts>
133
134 No certificates will be output.
135
136 =item B<-noout>
137
138 This option inhibits all credentials output,
139 and so the input is just verified.
140
141 =item B<-legacy>
142
143 Use legacy mode of operation and automatically load the legacy provider.
144 If OpenSSL is not installed system-wide,
145 it is necessary to also use, for example, C<-provider-path ./providers>
146 or to set the environment variable B<OPENSSL_MODULES>
147 to point to the directory where the providers can be found.
148
149 In the legacy mode, the default algorithm for certificate encryption
150 is RC2_CBC or 3DES_CBC depending on whether the RC2 cipher is enabled
151 in the build. The default algorithm for private key encryption is 3DES_CBC.
152 If the legacy option is not specified, then the legacy provider is not loaded
153 and the default encryption algorithm for both certificates and private keys is
154 AES_256_CBC with PBKDF2 for key derivation.
155
156 {- $OpenSSL::safe::opt_engine_item -}
157
158 {- $OpenSSL::safe::opt_provider_item -}
159
160 {- $OpenSSL::safe::opt_r_item -}
161
162 =back
163
164 =head2 PKCS#12 input (parsing) options
165
166 =over 4
167
168 =item B<-in> I<filename>|I<uri>
169
170 This specifies the input filename or URI.
171 Standard input is used by default.
172 Without the B<-export> option this must be PKCS#12 file to be parsed.
173 For use with the B<-export> option
174 see the L</PKCS#12 output (export) options> section.
175
176 =item B<-out> I<filename>
177
178 The filename to write certificates and private keys to, standard output by
179 default. They are all written in PEM format.
180
181 =item B<-info>
182
183 Output additional information about the PKCS#12 file structure, algorithms
184 used and iteration counts.
185
186 =item B<-nomacver>
187
188 Don't attempt to verify the integrity MAC.
189
190 =item B<-clcerts>
191
192 Only output client certificates (not CA certificates).
193
194 =item B<-cacerts>
195
196 Only output CA certificates (not client certificates).
197
198 =item B<-aes128>, B<-aes192>, B<-aes256>
199
200 Use AES to encrypt private keys before outputting.
201
202 =item B<-aria128>, B<-aria192>, B<-aria256>
203
204 Use ARIA to encrypt private keys before outputting.
205
206 =item B<-camellia128>, B<-camellia192>, B<-camellia256>
207
208 Use Camellia to encrypt private keys before outputting.
209
210 =item B<-des>
211
212 Use DES to encrypt private keys before outputting.
213
214 =item B<-des3>
215
216 Use triple DES to encrypt private keys before outputting.
217
218 =item B<-idea>
219
220 Use IDEA to encrypt private keys before outputting.
221
222 =item B<-noenc>
223
224 Don't encrypt private keys at all.
225
226 =item B<-nodes>
227
228 This option is deprecated since OpenSSL 3.0; use B<-noenc> instead.
229
230 =back
231
232 =head2 PKCS#12 output (export) options
233
234 =over 4
235
236 =item B<-export>
237
238 This option specifies that a PKCS#12 file will be created rather than
239 parsed.
240
241 =item B<-out> I<filename>
242
243 This specifies filename to write the PKCS#12 file to. Standard output is used
244 by default.
245
246 =item B<-in> I<filename>|I<uri>
247
248 This specifies the input filename or URI.
249 Standard input is used by default.
250 With the B<-export> option this is a file with certificates and a key,
251 or a URI that refers to a key accessed via an engine.
252 The order of credentials in a file doesn't matter but one private key and
253 its corresponding certificate should be present. If additional
254 certificates are present they will also be included in the PKCS#12 output file.
255
256 =item B<-inkey> I<filename>|I<uri>
257
258 The private key input for PKCS12 output.
259 If this option is not specified then the input file (B<-in> argument) must
260 contain a private key.
261 If no engine is used, the argument is taken as a file.
262 If the B<-engine> option is used or the URI has prefix C<org.openssl.engine:>
263 then the rest of the URI is taken as key identifier for the given engine.
264
265 =item B<-certfile> I<filename>
266
267 An input file with extra certificates to be added to the PKCS#12 output
268 if the B<-export> option is given.
269
270 =item B<-passcerts> I<arg>
271
272 The password source for certificate input such as B<-certfile>
273 and B<-untrusted>.
274 For more information about the format of B<arg> see
275 L<openssl-passphrase-options(1)>.
276
277 =item B<-chain>
278
279 If this option is present then the certificate chain of the end entity
280 certificate is built and included in the PKCS#12 output file.
281 The end entity certificate is the first one read from the B<-in> file
282 if no key is given, else the first certificate matching the given key.
283 The standard CA trust store is used for chain building,
284 as well as any untrusted CA certificates given with the B<-untrusted> option.
285
286 =item B<-untrusted> I<filename>
287
288 An input file of untrusted certificates that may be used
289 for chain building, which is relevant only when a PKCS#12 file is created
290 with the B<-export> option and the B<-chain> option is given as well.
291 Any certificates that are actually part of the chain are added to the output.
292
293 {- $OpenSSL::safe::opt_trust_item -}
294
295 =item B<-name> I<friendlyname>
296
297 This specifies the "friendly name" for the certificates and private key. This
298 name is typically displayed in list boxes by software importing the file.
299
300 =item B<-caname> I<friendlyname>
301
302 This specifies the "friendly name" for other certificates. This option may be
303 used multiple times to specify names for all certificates in the order they
304 appear. Netscape ignores friendly names on other certificates whereas MSIE
305 displays them.
306
307 =item B<-CSP> I<name>
308
309 Write I<name> as a Microsoft CSP name.
310 The password source for the input, and for encrypting any private keys that
311 are output.
312 For more information about the format of B<arg>
313 see L<openssl-passphrase-options(1)>.
314
315 =item B<-LMK>
316
317 Add the "Local Key Set" identifier to the attributes.
318
319 =item B<-keyex>|B<-keysig>
320
321 Specifies that the private key is to be used for key exchange or just signing.
322 This option is only interpreted by MSIE and similar MS software. Normally
323 "export grade" software will only allow 512 bit RSA keys to be used for
324 encryption purposes but arbitrary length keys for signing. The B<-keysig>
325 option marks the key for signing only. Signing only keys can be used for
326 S/MIME signing, authenticode (ActiveX control signing) and SSL client
327 authentication, however, due to a bug only MSIE 5.0 and later support
328 the use of signing only keys for SSL client authentication.
329
330 =item B<-keypbe> I<alg>, B<-certpbe> I<alg>
331
332 These options allow the algorithm used to encrypt the private key and
333 certificates to be selected. Any PKCS#5 v1.5 or PKCS#12 PBE algorithm name
334 can be used (see L</NOTES> section for more information). If a cipher name
335 (as output by C<openssl list -cipher-algorithms>) is specified then it
336 is used with PKCS#5 v2.0. For interoperability reasons it is advisable to only
337 use PKCS#12 algorithms.
338
339 Special value C<NONE> disables encryption of the private key and certificates.
340
341 =item B<-descert>
342
343 Encrypt the certificates using triple DES. By default the private
344 key and the certificates are encrypted using AES-256-CBC unless
345 the '-legacy' option is used. If '-descert' is used with the '-legacy'
346 then both, the private key and the certificates are encrypted using triple DES.
347
348 =item B<-macalg> I<digest>
349
350 Specify the MAC digest algorithm. If not included SHA256 will be used.
351
352 =item B<-pbmac1_pbkdf2>
353
354 Use PBMAC1 with PBKDF2 for MAC protection of the PKCS#12 file.
355
356 =item B<-pbmac1_pbkdf2_md> I<digest>
357
358 Specify the PBKDF2 KDF digest algorithm. If not specified, SHA256 will be used.
359 Unless C<-pbmac1_pbkdf2> is specified, this parameter is ignored.
360
361 =item B<-iter> I<count>
362
363 This option specifies the iteration count for the encryption key and MAC. The
364 default value is 2048.
365
366 To discourage attacks by using large dictionaries of common passwords the
367 algorithm that derives keys from passwords can have an iteration count applied
368 to it: this causes a certain part of the algorithm to be repeated and slows it
369 down. The MAC is used to check the file integrity but since it will normally
370 have the same password as the keys and certificates it could also be attacked.
371
372 =item B<-noiter>, B<-nomaciter>
373
374 By default both encryption and MAC iteration counts are set to 2048, using
375 these options the MAC and encryption iteration counts can be set to 1, since
376 this reduces the file security you should not use these options unless you
377 really have to. Most software supports both MAC and encryption iteration counts.
378 MSIE 4.0 doesn't support MAC iteration counts so it needs the B<-nomaciter>
379 option.
380
381 =item B<-maciter>
382
383 This option is included for compatibility with previous versions, it used
384 to be needed to use MAC iterations counts but they are now used by default.
385
386 =item B<-macsaltlen>
387
388 This option specifies the salt length in bytes for the MAC. The salt length
389 should be at least 16 bytes as per NIST SP 800-132. The default value
390 is 8 bytes for backwards compatibility.
391
392 =item B<-nomac>
393
394 Do not attempt to provide the MAC integrity. This can be useful with the FIPS
395 provider as the PKCS12 MAC requires PKCS12KDF which is not an approved FIPS
396 algorithm and cannot be supported by the FIPS provider.
397
398 =item B<-jdktrust>
399
400 Export pkcs12 file in a format compatible with Java keystore usage. This option
401 accepts a string parameter indicating the trust oid name to be granted to the
402 certificate it is associated with. Currently only "anyExtendedKeyUsage" is
403 defined. Note that, as Java keystores do not accept PKCS12 files with both
404 trusted certificates and keypairs, use of this option implies the setting of the
405 B<-nokeys> option
406
407 =back
408
409 =head1 NOTES
410
411 Although there are a large number of options most of them are very rarely
412 used. For PKCS#12 file parsing only B<-in> and B<-out> need to be used
413 for PKCS#12 file creation B<-export> and B<-name> are also used.
414
415 If none of the B<-clcerts>, B<-cacerts> or B<-nocerts> options are present
416 then all certificates will be output in the order they appear in the input
417 PKCS#12 files. There is no guarantee that the first certificate present is
418 the one corresponding to the private key.
419 Certain software which tries to get a private key and the corresponding
420 certificate might assume that the first certificate in the file is the one
421 corresponding to the private key, but that may not always be the case.
422 Using the B<-clcerts> option will solve this problem by only
423 outputting the certificate corresponding to the private key. If the CA
424 certificates are required then they can be output to a separate file using
425 the B<-nokeys> B<-cacerts> options to just output CA certificates.
426
427 The B<-keypbe> and B<-certpbe> algorithms allow the precise encryption
428 algorithms for private keys and certificates to be specified. Normally
429 the defaults are fine but occasionally software can't handle triple DES
430 encrypted private keys, then the option B<-keypbe> I<PBE-SHA1-RC2-40> can
431 be used to reduce the private key encryption to 40 bit RC2. A complete
432 description of all algorithms is contained in L<openssl-pkcs8(1)>.
433
434 Prior 1.1 release passwords containing non-ASCII characters were encoded
435 in non-compliant manner, which limited interoperability, in first hand
436 with Windows. But switching to standard-compliant password encoding
437 poses problem accessing old data protected with broken encoding. For
438 this reason even legacy encodings is attempted when reading the
439 data. If you use PKCS#12 files in production application you are advised
440 to convert the data, because implemented heuristic approach is not
441 MT-safe, its sole goal is to facilitate the data upgrade with this
442 command.
443
444 =head1 EXAMPLES
445
446 Parse a PKCS#12 file and output it to a PEM file:
447
448 openssl pkcs12 -in file.p12 -out file.pem
449
450 Output only client certificates to a file:
451
452 openssl pkcs12 -in file.p12 -clcerts -out file.pem
453
454 Don't encrypt the private key:
455
456 openssl pkcs12 -in file.p12 -out file.pem -noenc
457
458 Print some info about a PKCS#12 file:
459
460 openssl pkcs12 -in file.p12 -info -noout
461
462 Print some info about a PKCS#12 file in legacy mode:
463
464 openssl pkcs12 -in file.p12 -info -noout -legacy
465
466 Create a PKCS#12 file from a PEM file that may contain a key and certificates:
467
468 openssl pkcs12 -export -in file.pem -out file.p12 -name "My PSE"
469
470 Include some extra certificates:
471
472 openssl pkcs12 -export -in file.pem -out file.p12 -name "My PSE" \
473 -certfile othercerts.pem
474
475 Export a PKCS#12 file with data from a certificate PEM file and from a further
476 PEM file containing a key, with default algorithms as in the legacy provider:
477
478 openssl pkcs12 -export -in cert.pem -inkey key.pem -out file.p12 -legacy
479
480 =head1 SEE ALSO
481
482 L<openssl(1)>,
483 L<openssl-pkcs8(1)>,
484 L<ossl_store-file(7)>
485
486 =head1 HISTORY
487
488 The B<-engine> option was deprecated in OpenSSL 3.0.
489 The B<-nodes> option was deprecated in OpenSSL 3.0, too; use B<-noenc> instead.
490
491 =head1 COPYRIGHT
492
493 Copyright 2000-2025 The OpenSSL Project Authors. All Rights Reserved.
494
495 Licensed under the Apache License 2.0 (the "License"). You may not use
496 this file except in compliance with the License. You can obtain a copy
497 in the file LICENSE in the source distribution or at
498 L<https://www.openssl.org/source/license.html>.
499
500 =cut
501