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