If you've spent any time configuring user authentication on... Full Story
By Manny Fernandez
August 30, 2022
Extracting Your Private Key from a .pfx certificate
I had a customer that installed a wildcard certificate on an Exchange server. Later they wanted to use the same wildcard on another server, which is the purpose of the wildcard certificate, and he did not have the private key for the certificate. Normally, you need three things to use a wildcard certificate: certificate file, the key file (Unencrypted) and the password used.
In this example, I am going to use a fictitious certificate.
First things first. I went to the Exchange Server where they had the certificate installed. They had created the CSR on this server, thus the private key was ALSO on this server. Went to the Start button and type Certificate and used the Windows native certificate utility. Once there, I found the certificate in question and right-clicked on it and chose to export. You will want to choose the export with private key as the option and ensure to choose .pfx as the type.
You will now need OpenSSL available by default on macOS and Linux. For Windows, you will need to download and install it.
Once you have the certificate file in PFX and OpenSSL, you are ready to go:
The first thing we are going to do is extract the encrypted key file from the pfx certificate. You are going to need the password that was created when the original CSR was being created.

But before that, you want to make sure you are in the correct folder. You can give the pwd in macOS or Linux which stands for Print Working Directory (when people called then directories and not folders).
As you can see, I have my newly exported .pfx file.

In my example, I named it star-monkey.pfx (you can name it whatever you want but I like having the star or * in the name so I know its a wildcard certificate).
Extracting the Encrypted Private Key
Now, we are going to run our first OpenSSL command.
openssl pkcs12 -in star-monkey.pfx -nocerts -out monkey-encrypted.key

As you can see in the screenshot, it will ask you for the password. You are looking for the MAC verified OK output.
This output file will be encrypted and not really useful in most cases.
![]()
For validation, run the ls command (or dir in Windows)
Extracting the Certificate Portion of the Key
The next command will extract the certificate portion from the .pfx file, once again, you will need the password.

As you can see, we are once again looking for the MAC verified OK output as we did in the previous command.
Decrypting the Encrypted Key file from the .pfx certificate
Finally, we will run the following command to decrypt the encrypted private key.
openssl rsa -in monkey-encrypted.key -out monkey.key
This will ask you for the original password as well as the password you used to export it from Windows in the above step.

Now you can successfully import this certificate, key and password into nay server or firewall.
Hope this helps.
Recent posts
-
-
DNS is one of those technologies that quietly underpins... Full Story
-
BGP issues on FortiGate firewalls usually trace back to... Full Story
-
Every time your laptop talks to your router, a... Full Story
-
If you've spent any time configuring NAT on a... Full Story
-
If you have spent any time configuring firewall policies... Full Story
-
High availability on FortiGate is one of those features... Full Story
-
If you've configured SD-WAN on a FortiGate, you've almost... Full Story
-
FortiLink is the management protocol that turns a FortiSwitch... Full Story
-
FortiSwitches are pretty rock solid from Mean Time Between... Full Story
-
This is a quicky tip. Have you ever gone... Full Story
-
DNS is one of those quiet pieces of internet... Full Story
-
This article is an updated version of the previous... Full Story
-
You will add ns2 as a secondary (slave) BIND9... Full Story
-
In the process of deploying my lab, I needed... Full Story
-
RFC 8805, used to be known as Self-Correcting IP... Full Story
-
Years back, I wrote an article about certificate pinning. ... Full Story
-
FortiGates have the ability to send alerts to Microsoft... Full Story
-
In this post, I am going to walk through... Full Story
-
Troubleshooting VoIP on a FortiGate can feel like trying... Full Story
-
Prior to FortiOS 7.0, there were three commands to... Full Story
-
In this post, I am going to go over... Full Story
-
What we are going to do: We are going... Full Story
-
Choosing between FGCP (FortiGate Clustering Protocol) and FGSP (FortiGate... Full Story
-
Creating a VLAN on macOS (The "Pro" Move) A... Full Story
-
This blog post explores the logic behind how macOS... Full Story
-
Pretty Fly for a Wi-Fi Tell My Wi-Fi Love... Full Story
-
Part of my daily gig is creating BoMs (Bill-of-Materials)... Full Story
-
ICMP introduces several security risks, but careful filtering, rate... Full Story
-
The command diag debug application dhcps -1 enables full... Full Story
-
In the world of FortiOS, execute tac report is... Full Story
-
LLDP; What is it The Link Layer Discovery Protocol... Full Story
-
What it actually does When you run diagnose fdsm... Full Story
-
Monkey Bites are bite-sized, high-impact security insights designed for... Full Story
-
I have run macOS in macOS with Parallels but... Full Story
-
Don't be confused with my other FortiNAC posts where... Full Story
-
This is the third session in a multi-part article... Full Story
-
Today I was configuring key-based authentication on a FortiGate... Full Story
-
Netcat, often called the "Swiss Army knife" of networking,... Full Story
-
At its core, IEEE 802.1X is a network layer... Full Story
-
In case you did not see the previous FortiNAC... Full Story
-
This is our 5th session where we are going... Full Story
-
Now that we have Wireshark installed and somewhat configured,... Full Story
-
The Philosophy of Packet Analysis Troubleshooting isn't about looking... Full Story
-
Executive Summary A FortiGate is only as flexible as... Full Story
-
1. Title & Executive Summary Objective: This guide explains... Full Story
-
1. Title and Executive Summary Title: Power over Ethernet Standards... Full Story