Export Certificates and Private Key from a PKCS#12 File with OpenSSL - SSL.com (2024)

Note: This article does not apply to SSL.com code signing and document signing certificates. The private keys of these types of certificates cannot be exported and they cannot be generated as .pfx files. SSL.com code signing and document signing certificates and their private keys can only be generated and stored in the eSigner cloud signing environment, a Yubikey device, or a supported Cloud HSM.

This how-to will walk you through extracting information from a PKCS#12 file with OpenSSL. PKCS#12 (also known as PKCS12 or PFX) is a binary format for storing a certificate chain and private key in a single, encryptable file. PKCS#12 files are commonly used to import and export certificates and private keys on Windows and macOS computers, and usually have the filename extensions .p12 or .pfx.

For more helpful how-tos and the latest cybersecurity news, sign up for SSL.com’s newsletter here:

What is OpenSSL?
OpenSSL is a very useful open-source command-line toolkit for working with X.509 certificates, certificate signing requests (CSRs), and cryptographic keys. If you are using a UNIX variant like Linux or macOS, OpenSSL is probably already installed on your computer. If you would like to use OpenSSL on Windows, you can enable Windows 10’s Linux subsystem or install Cygwin. You can also easily create a PKCS#12 file with openSSL.

SSL.com provides a wide variety of SSL/TLS server certificates for HTTPS websites.

COMPARE SSL/TLS CERTIFICATES

Video

https://www.youtube.com/watch?v=S_imVMFOdhU

Go to top

In all of the examples shown below, substitute the names of the files you are actually working with for INFILE.p12, OUTFILE.crt, and OUTFILE.key.

View PKCS#12 Information on Screen

To dump all of the information in a PKCS#12 file to the screen in PEM format, use this command:

openssl pkcs12 -info -in INFILE.p12 -nodes

You will then be prompted for the PKCS#12 file’s password:

Enter Import Password:

Type the password entered when creating the PKCS#12 file and press enter. OpenSSL will output any certificates and private keys in the file to the screen:

Bag Attributes localKeyID: AC 3E 77 9A 99 62 84 3D 77 CB 44 0D F9 78 57 7C 08 28 05 97 subject=/CN=Aaron Russell/emailAddress=*********@gmail.comissuer=/C=US/ST=Texas/L=Houston/O=SSL Corp/CN=SSL.com Client Certificate Intermediate CA RSA R1-----BEGIN CERTIFICATE-----MIIF1DCCA7ygAwIBAgIQcOrAJCMayJsZBKJsyz/aQDANBgkqhkiG9w0BAQsFADB+MQswCQYDVQQGEwJVUzEOMAwGA1UECAwFVGV4YXMxEDAOBgNVBAcMB0hvdXN0b24xETAPBgNVBAoMCFNTTCBDb3JwMTowOAYDVQQDDDFTU0wuY29tIENsaWVudCBDZXJ0...bwK6ABAZUq6QcvhD0LYsXya+ncDCR6wxb9E0DWd4ATQMzxGTu/yE3kT+9Ef6IY+narmh3HZUfan2Hb64YD0tjLMca/PC+sKAZu28gB/3HQRHIFugvh6RO3bIoorl0jUg1Ml2r83++biS0HL6JdcwuuUF-----END PRIVATE KEY-----

Encrypt Private Key

If you would like to encrypt the private key and protect it with a password before output, simply omit the -nodes flag from the command:

openssl pkcs12 -info -in INFILE.p12

In this case, you will be prompted to enter and verify a new password after OpenSSL outputs any certificates, and the private key will be encrypted (note that the text of the key begins with -----BEGIN ENCRYPTED PRIVATE KEY-----):

Enter PEM pass phrase:Verifying - Enter PEM pass phrase:-----BEGIN ENCRYPTED PRIVATE KEY-----MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIGwhJIMXRiLQCAggAMBQGCCqGSIb3DQMHBAiXdeymTYuedgSCBMjwGg78PsqiNJLfpDFbMxL98u3tK9Cs...SGVCCBj5vBpSbBXAGbOv74h4satKmAMgGc8SgU06geS9gFgt/wLwehMJ/H4BSmex4S/2tYzZrDBJkfH9JpggubYRTgwfa*gY2BkX03dK2sqfu+QVTVTKMj2VI0sKcFfLZbdw=-----END ENCRYPTED PRIVATE KEY-----

Extract Only Certificates or Private Key

If you only want to output the private key, add -nocerts to the command:

openssl pkcs12 -info -in INFILE.p12 -nodes -nocerts

If you only need the certificates, use -nokeys (and since we aren’t concerned with the private key we can also safely omit -nodes):

openssl pkcs12 -info -in INFILE.p12 -nokeys

Go to top

Save Certificates and Private Keys to Files

You can export the certificates and private key from a PKCS#12 file and save them in PEM format to a new file by specifying an output filename:

openssl pkcs12 -in INFILE.p12 -out OUTFILE.crt -nodes

Again, you will be prompted for the PKCS#12 file’s password. As before, you can encrypt the private key by removing the -nodes flag from the command and/or add -nocerts or -nokeys to output only the private key or certificates. So, to generate a private key file, we can use this command:

openssl pkcs12 -in INFILE.p12 -out OUTFILE.key -nodes -nocerts

And to create a file including only the certificates, use this:

openssl pkcs12 -in INFILE.p12 -out OUTFILE.crt -nokeys

Go to top

Convert Private Key to PKCS#1 Format

The examples above all output the private key in OpenSSL’s default PKCS#8 format. If you know you need PKCS#1 instead, you can pipe the output of the OpenSSL’s PKCS#12 utility to its RSA or EC utility depending on the key type. Both of the commands below will output a key file in PKCS#1 format:

RSA

openssl pkcs12 -in INFILE.p12 -nodes -nocerts | openssl rsa -out OUTFILE.key

ECDSA

openssl pkcs12 -in INFILE.p12 -nodes -nocerts | openssl ec -out OUTFILE.key

Note: You can tell the difference between PKCS#8 and PKCS#1 private key files by looking at the first line of text. PKCS#1 files will specify the algorithm:
-----BEGIN RSA PRIVATE KEY-----

PKCS#8 files do not show the algorithm, and may also be encrypted:
-----BEGIN PRIVATE KEY-----
or
-----BEGIN ENCRYPTED PRIVATE KEY-----


Thank you for choosing SSL.com! If you have any questions, please contact us by email at [email protected], call 1-877-SSL-SECURE, or just click the chat link at the bottom right of this page.

Export Certificates and Private Key from a PKCS#12 File with OpenSSL - SSL.com (2024)
Top Articles
Obsidian
First anniversary: Ghana is now richer than Nigeria, says Bismark Rewane
Section 4Rs Dodger Stadium
Kansas City Kansas Public Schools Educational Audiology Externship in Kansas City, KS for KCK public Schools
Terrorist Usually Avoid Tourist Locations
Tabc On The Fly Final Exam Answers
Top Financial Advisors in the U.S.
Retro Ride Teardrop
Flights to Miami (MIA)
Wal-Mart 140 Supercenter Products
CA Kapil 🇦🇪 Talreja Dubai on LinkedIn: #businessethics #audit #pwc #evergrande #talrejaandtalreja #businesssetup…
Baseball-Reference Com
The Blind Showtimes Near Showcase Cinemas Springdale
Hmr Properties
Med First James City
I Wanna Dance with Somebody : séances à Paris et en Île-de-France - L'Officiel des spectacles
Guilford County | NCpedia
2 Corinthians 6 Nlt
Wicked Local Plymouth Police Log 2022
Vistatech Quadcopter Drone With Camera Reviews
Voy Boards Miss America
U Arizona Phonebook
Keurig Refillable Pods Walmart
Cbssports Rankings
A Person That Creates Movie Basis Figgerits
Craigslist Apartments Baltimore
TeamNet | Agilio Software
Bra Size Calculator & Conversion Chart: Measure Bust & Convert Sizes
Wku Lpn To Rn
John Philip Sousa Foundation
Ncal Kaiser Online Pay
Hannah Jewell
Duke Energy Anderson Operations Center
Landing Page Winn Dixie
Gideon Nicole Riddley Read Online Free
Gabrielle Enright Weight Loss
404-459-1280
Tendermeetup Login
Sunrise Garden Beach Resort - Select Hurghada günstig buchen | billareisen.at
Sabrina Scharf Net Worth
Clausen's Car Wash
Emily Browning Fansite
N33.Ultipro
Gt500 Forums
The Blackening Showtimes Near Ncg Cinema - Grand Blanc Trillium
Kate Spade Outlet Altoona
Gander Mountain Mastercard Login
The top 10 takeaways from the Harris-Trump presidential debate
Smoke From Street Outlaws Net Worth
Www Ventusky
Morbid Ash And Annie Drew
Festival Gas Rewards Log In
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 6285

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.