OPENSSL-PKCS12(1SSL)
๐ NAME ๐
okay so you're reading the openssl-pkcs12 page from the OpenSSL manual set (that's the 1SSL corner of the man pages, bestie ๐
) โ and it's the PKCS#12 file command, which is a whole entire vibe: it makes PKCS#12 files and it reads them back. ๐
โจ SYNOPSIS โจ
no cap, here's the shape of it:
openssl pkcs12 [-help] [-passin arg] [-passout arg] [-password arg]
[-twopass] [-in filename|uri] [-out filename] [-nokeys] [-nocerts]
[-noout] [-legacy] [-provider name] [-provider-path path] [-provparam
[name:]key=value] [-propquery propq] [-rand files] [-writerand file]
PKCS#12 input (parsing) options: [-info] [-nomacver] [-clcerts]
[-cacerts]
[-aes128] [-aes192] [-aes256] [-aria128] [-aria192] [-aria256]
[-camellia128] [-camellia192] [-camellia256] [-des] [-des3] [-idea]
[-noenc] [-nodes]
PKCS#12 output (export) options:
[-export] [-inkey filename|uri] [-certfile filename] [-passcerts arg]
[-chain] [-untrusted filename] [-CAfile file] [-no-CAfile] [-CApath dir]
[-no-CApath] [-CAstore uri] [-no-CAstore] [-name name] [-caname name]
[-CSP name] [-LMK] [-keyex] [-keysig] [-keypbe cipher] [-certpbe cipher]
[-descert] [-macalg digest] [-pbmac1_pbkdf2] [-pbmac1_pbkdf2_md digest]
[-iter count] [-noiter] [-nomaciter] [-maciter] [-macsaltlen] [-nomac]
[-jdktrust usage]
see how the flags come in groups? that's not an accident, and it's actually the key to the whole page, so hold that thought ๐ซถ
๐ธ DESCRIPTION ๐ธ
so this command is the one that lets you create PKCS#12 files and parse them โ and yes, PKCS#12 files are also called PFX files, same thing, different nickname, iconic behavior honestly โจ
and these files are everywhere, like not just an OpenSSL thing โ a bunch of other programs use them too, including Netscape, MSIE and MS Outlook. so when you hand someone a .p12, you're speaking a language a lot of software already understands ๐ซ
๐ OPTIONS ๐
okay bestie, gentle heads up: there are a lot of options here, and some of their meanings literally depend on whether you're creating a PKCS#12 file or parsing one. the way that works is:
- by default, a PKCS#12 file is parsed. ๐
- a PKCS#12 file gets created when you use the
-exportoption (more on that below).
so the PKCS#12 export encryption and MAC options โ stuff like -certpbe and -iter, plus a whole bunch of further options like -chain โ are only relevant with -export. and conversely? the options about encrypting private keys when you're outputting PKCS#12 input are relevant only when -export is not given. it's giving "read the room, the flags know which mode they're in" ๐
the default encryption algorithm is AES-256-CBC with PBKDF2 for key derivation. not me being fancy, that's just the default ๐ง
and if you hit problems loading legacy PKCS#12 files โ like ones involvingRC2-40-CBCfor example โ try the-legacyoption, and if you need it, the-provider-pathoption too. that combo is the move. ๐ฅ
here we go, the actual list:
-helpโ prints out a usage message. the classic. ๐-passin argโ the password source for input files. with-export, it's what decrypts the input private key. otherwise? it's the password for the input PKCS#12 file. for more info on the format of arg check outopenssl-passphrase-options(1). ๐ซถ-passout argโ the password source for output files. with-export, it's the password for the output PKCS#12 file. otherwise, it's used to encrypt any private keys that are output. format of arg again lives inopenssl-passphrase-options(1). โจ-password argโ with-export,-passwordis literally equivalent to-passout. otherwise it's equivalent to-passin. same energy, different costume ๐-twopassโ prompts for separate integrity and encryption passwords. โ ๏ธ big dramatic warning: most software always assumes these two are the same, so this option will render such PKCS#12 files unreadable by that software. cannot be used in combination with the options-password,-passinif importing from PKCS#12, or-passoutif exporting. so yeah, it's giving "chaos mode, choose wisely" ๐ญ-nokeysโ no private keys will be output. periodt.-nocertsโ no certificates will be output. ๐-nooutโ this option inhibits all credentials output, so the input is just verified. that's it, that's the whole job โจ-legacyโ use legacy mode of operation and automatically load the legacy provider. ๐ง if OpenSSL isn't installed system-wide, you also need to use, for example,-provider-path ./providers, or set the environment variableOPENSSL_MODULESto point at the directory where the providers can be found.
in legacy mode, the default algorithm for certificate encryption is RC2_CBC or 3DES_CBC, depending on whether the RC2 cipher is enabled in the build. the default algorithm for private key encryption is 3DES_CBC. but if the legacy option is not specified, then the legacy provider is not loaded, and the default encryption algorithm for both certificates and private keys is AES_256_CBC with PBKDF2 for key derivation. so it's a whole different default vibe depending on that one flag ๐
-provider name-provider-path path-provparam [name:]key=value-propquery propqโ these four? go read"Provider Options"inopenssl(1), plusprovider(7)andproperty(7). iykyk ๐-rand files,-writerand fileโ see"Random State Options"inopenssl(1)for details. ๐ฒ
๐ฆ PKCS#12 input (parsing) options ๐ฆ
this is the "read my file, please" zone:
-in filename|uriโ specifies the input filename or URI. standard input is used by default. without the-exportoption, this must be the PKCS#12 file to be parsed. for use with the-exportoption, see the"PKCS#12 output (export) options"section. ๐-out filenameโ the filename to write certificates and private keys to; standard output by default. they're all written in PEM format. ๐ฅ-infoโ outputs additional information about the PKCS#12 file structure, the algorithms used, and iteration counts. it's giving "tell me everything, i want the lore" ๐-nomacverโ don't attempt to verify the integrity MAC. skipping the vibe check, bold of you ๐ญ-clcertsโ only output client certificates (not CA certificates). ๐-cacertsโ only output CA certificates (not client certificates). the mirror twin โจ-aes128,-aes192,-aes256โ use AES to encrypt private keys before outputting. ๐-aria128,-aria192,-aria256โ use ARIA to encrypt private keys before outputting. ๐-camellia128,-camellia192,-camellia256โ use Camellia to encrypt private keys before outputting. ๐ธ-desโ use DES to encrypt private keys before outputting. old-school, okay ๐ซถ-des3โ use triple DES to encrypt private keys before outputting. ๐ง-ideaโ use IDEA to encrypt private keys before outputting. ๐-noencโ don't encrypt private keys at all. zero encryption, zero chill ๐-nodesโ this option is deprecated since OpenSSL 3.0; use-noencinstead. so like, it still exists, but it's the old baddie, not the current one. โ ๏ธ
๐ PKCS#12 output (export) options ๐
and this is the "make me a file" zone:
-exportโ this option specifies that a PKCS#12 file will be created rather than parsed. the main character flag of this whole section ๐-out filenameโ specifies the filename to write the PKCS#12 file to. standard output is used by default. โจ-in filename|uriโ specifies the input filename or URI. standard input is used by default. with the-exportoption, this is a file with certificates and a key. here's the tea: the order of credentials in a file doesn't matter, but one private key and its corresponding certificate should be present. if additional certificates are present, they'll also be included in the PKCS#12 output file. ๐ซถ-inkey filename|uriโ the input filename for the private key for PKCS12 output. if this option isn't specified, then the input file (the-inargument) must contain a private key. no key, no party ๐-certfile filenameโ an input file with extra certificates to be added to the PKCS#12 output, if the-exportoption is given. bonus certs, why not ๐-passcerts argโ the password source for certificate input, like-certfileand-untrusted. for more information about the format of arg seeopenssl-passphrase-options(1). ๐-chainโ if this option is present, then the certificate chain of the end entity certificate is built and included in the PKCS#12 output file. the end entity certificate is the first one read from the-infile if no key is given, else the first certificate matching the given key. the standard CA trust store is used for chain building, plus any untrusted CA certificates given with the-untrustedoption. so it's building the whole family tree ๐ณ-untrusted filenameโ an input file of untrusted certificates that may be used for chain building โ relevant only when a PKCS#12 file is created with the-exportoption and the-chainoption is given as well. any certificates that are actually part of the chain get added to the output. ๐ฆ-CAfile file,-no-CAfile,-CApath dir,-no-CApath,-CAstore uri,-no-CAstoreโ see"Trusted Certificate Options"inopenssl-verification-options(1)for details. ๐-name friendlynameโ specifies the"friendly name"for the certificates and private key. this name is typically displayed in list boxes by software importing the file. it's giving "hi, my name is" ๐-caname friendlynameโ specifies the"friendly name"for other certificates. this option may be used multiple times to specify names for all certificates in the order they appear. Netscape ignores friendly names on other certificates, whereas MSIE displays them. so, drama between old browsers, classic ๐ญ-CSP nameโ write name as a Microsoft CSP name. the password source for the input, and for encrypting any private keys that are output. for more information about the format of arg seeopenssl-passphrase-options(1). ๐ช-LMKโ add the"Local Key Set"identifier to the attributes. ๐-keyex|-keysigโ specifies that the private key is to be used for key exchange, or just signing. this option is only interpreted by MSIE and similar MS software. normally,"export grade"software will only allow 512 bit RSA keys to be used for encryption purposes, but arbitrary length keys for signing. the-keysigoption marks the key for signing only. signing only keys can be used for S/MIME signing, authenticode (ActiveX control signing) and SSL client authentication โ however, โ ๏ธ due to a bug, only MSIE 5.0 and later support the use of signing only keys for SSL client authentication. a bug! in the manual! we love transparency ๐-keypbe alg,-certpbe algโ these options let you select the algorithm used to encrypt the private key and certificates. any PKCS#5 v1.5 or PKCS#12 PBE algorithm name can be used (see the"NOTES"section for more information). if a cipher name (as output byopenssl list -cipher-algorithms) is specified, then it's used with PKCS#5 v2.0. for interoperability reasons it's advisable to only use PKCS#12 algorithms. ๐
special value NONE disables encryption of the private key and certificates. ๐ซ
-descertโ encrypt the certificates using triple DES. by default the private key and the certificates are encrypted usingAES-256-CBC, unless the-legacyoption is used. if-descertis used with the-legacy, then both the private key and the certificates are encrypted using triple DES. so it's a two-for-one deal in legacy land โจ-macalg digestโ specify the MAC digest algorithm. if not included,SHA256will be used. ๐งฎ-pbmac1_pbkdf2โ use PBMAC1 with PBKDF2 for MAC protection of the PKCS#12 file. ๐-pbmac1_pbkdf2_md digestโ specify the PBKDF2 KDF digest algorithm. if not specified,SHA256will be used. unless-pbmac1_pbkdf2is specified, this parameter is ignored. so don't @ it unless its friend is invited ๐-iter countโ specifies the iteration count for the encryption key and MAC. the default value is2048. ๐
To make dictionary attacks on your password just... not work, the algorithm that turns a password into a key can take an iteration count โจ โ it literally repeats part of the algorithm over and over and slows the whole thing wayyyyy down. And the MAC? That's the vibe check on file integrity ๐
but since it usually shares the same password as your keys and certs, it can get attacked too. Not me being thorough about security ๐ญ
-noiter,-nomaciterโ okay so by default both the encryption and MAC iteration counts are2048. These two options dial them all the way down to1, which โ bestie, hear me โ reduces your file security, so please don't use them unless you truly, actually have to ๐. Most software handles both MAC and encryption iteration counts fine. The one diva that doesn't isMSIE 4.0, which can't do MAC iteration counts at all, so it needs-nomaciter. That's it, that's the exception ๐-maciterโ this one's just here for compatibility with older versions ๐ซถ. It used to be needed to turn on MAC iteration counts, but now they're on by default, so it's basically a legacy baddie hanging around.-macsaltlenโ sets the salt length in bytes for the MAC ๐งโจ. PerNIST SP 800-132, that salt should be at least16bytes โ and hey,16is the default value. So the default already ate ๐ .-nomacโ don't even bother providing the MAC integrity check ๐ซ. The main character use case: the FIPS provider, because the PKCS12 MAC needsPKCS12KDF, which is not an approved FIPS algorithm and the FIPS provider straight up cannot support it ๐ญ.-jdktrustโ exports your pkcs12 file in a way that plays nice with Java keystore usage โ๐. It takes a string parameter naming the trust oid to be granted to the certificate it's associated with. As of right now, only"anyExtendedKeyUsage"is defined. And heads up ๐ข: Java keystores do not accept PKCS12 files that have both trusted certificates and keypairs, so using this option implies-nokeysgets set. Package deal, no cap.
๐ธ NOTES ๐ธ
Okay so there are a lot of options, but ngl, most of them are barely ever used ๐. For PKCS#12 file parsing you only need -in and -out. For PKCS#12 file creation you also need -export and -name. That's the whole starter pack ๐.
When you're loading with -in, an error will occur if the PKCS12 macdata contains PBMAC1 and the related PBKDF2 parameters are missing ๐ญ โ or if the associated key length isn't in the range 1 to 64. So like, keep those in range bestie.
If none of -clcerts, -cacerts or -nocerts are present, then all certificates get output, in the exact order they appear in the input PKCS#12 files โจ. And there is no guarantee that the first certificate present is the one matching the private key. Certain software that tries to grab a private key plus its corresponding certificate might assume the first cert in the file is the one for the private key โ but that may not always be the case ๐. The -clcerts option solves this whole situation by only outputting the certificate corresponding to the private key ๐. And if you need the CA certificates? Output them to a separate file with the -nokeys -cacerts options to get just the CA certificates. Chef's kiss, organized ๐
.
The -keypbe and -certpbe algorithms let you specify the precise encryption algorithms for private keys and certificates ๐. Normally the defaults are completely fine, but occasionally some software can't handle triple DES encrypted private keys โ in which case you can use the option -keypbe PBE-SHA1-RC2-40 to reduce the private key encryption down to 40 bit RC2. A complete description of all algorithms lives in openssl-pkcs8(1), go read it ๐ซถ.
History lesson time ๐: prior to the 1.1 release, passwords containing non-ASCII characters were encoded in a non-compliant manner, which limited interoperability โ in first hand with Windows ๐ญ. But switching to standard-compliant password encoding poses a problem for accessing old data protected with the broken encoding. For this reason, even legacy encodings are attempted when reading the data. If you use PKCS#12 files in a production application you are advised to convert the data, because the implemented heuristic approach is not MT-safe โ its sole goal is to facilitate the data upgrade with this command. So like, it's a crutch, not a lifestyle ๐.
โจ EXAMPLES โจ
Parse a PKCS#12 file and output it to a PEM file:
openssl pkcs12 -in file.p12 -out file.pem
Output only client certificates to a file:
openssl pkcs12 -in file.p12 -clcerts -out file.pem
Don't encrypt the private key:
openssl pkcs12 -in file.p12 -out file.pem -noenc
Print some info about a PKCS#12 file:
openssl pkcs12 -in file.p12 -info -noout
Print some info about a PKCS#12 file in legacy mode:
openssl pkcs12 -in file.p12 -info -noout -legacy
Create a PKCS#12 file from a PEM file that may contain a key and certificates:
openssl pkcs12 -export -in file.pem -out file.p12 -name "My PSE"
Include some extra certificates:
openssl pkcs12 -export -in file.pem -out file.p12 -name "My PSE" \
-certfile othercerts.pem
Export a PKCS#12 file with data from a certificate PEM file and from a further PEM file containing a key, with default algorithms as in the legacy provider:
openssl pkcs12 -export -in cert.pem -inkey key.pem -out file.p12 -legacy
๐ฆ SEE ALSO ๐ฆ
openssl(1), openssl-pkcs8(1), ossl_store-file(7)
๐ HISTORY ๐
The -nodes option was deprecated in OpenSSL 3.0, too โ use -noenc instead ๐
. The -macsaltlen option default changed from 8 to 16 bytes in OpenSSL 3.6. And the -engine option was removed in OpenSSL 4.0 ๐.
๐ COPYRIGHT ๐
Copyright 2000-2026 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's a wrap bestie!! ๐ โจ this whole glow-up is from OpenSSL version 4.0.3, dated 2026-09-29 โ go forth and pkcs12 responsibly, mwah ๐ซถ๐๐ธ
๐ฆ where this page comes from
- ubuntu stonking: openssl 4.0.3-1ubuntu1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms