Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Security»How to Extract Certificate and Private Key from PFX File

    How to Extract Certificate and Private Key from PFX File

    By RahulAugust 22, 20212 Mins Read

    A .PFX (Personal Information Exchange) file is used to store a certificate and its private and public keys. For example, if we need to transfer an SSL certificate from one windows server to another, You can simply export it as a .pfx file using IIS SSL export wizard or MMC console.

    Advertisement

    Sometimes we need to extract private keys and certificates from the .pfx file, but we can’t directly do it. This article can be helpful for you to do the same. This article will also be helpful for you to migrate an SSL certificate to AWS ELB because ELB required private keys and certificates separately.

    In order to use the below commands, you must have OpenSSL installed on your Windows or Linux system

    1. Extract the Private Key from PFX

    The following command will extract the private key from the .pfx file. A new file priv-key.pem will be generated in the current directory. This command will prompt a password set on the pfx file.

    openssl pkcs12 -in myfile.pfx -nocerts -out priv-key.pem -nodes 
    
    Command to Extract Private Key from PFX
    Command to Extract Private Key from PFX

    Open the result file (priv-key.pem) and copy text between and encluding —–BEGIN PRIVATE KEY—– and —–END PRIVATE KEY—– text.

    Extract Private Key from PFX
    Copy Private Key Content from Output File

    2. Extract the Certificate from PFX

    Next, extract the SSL certificate file from the pfx file. The following command will extract the certificate from the .pfx file and save it to the certificate.pem.

    openssl pkcs12 -in myfile.pfx -nokeys -out certificate.pem 
    
    How to Extract SSL Certificate from PFX
    Command to Extract SSL Certificate from PFX

    Open the result file (certificate.pem) and copy text between and encluding —–BEGIN CERTIFICATE—– and —–END CERTIFICATE—– text. This file may also include the other certificate chain. The first block will be your domain certificate and the others will be the chain. You can copy all the certificates in one file and use it.

    Extract Private Key from PFX
    Copy the Private Key Content from Output

    Conclusion

    In this how-to guide, you have learned to extract certificates and private keys from a PFX file. It is more helpful for migrating SSL certificates from Windows to Linux servers.

    crt csr extract pfx pfx
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to block bad bots using .htaccess

    How to Open Port in Linux

    How to Install and Configure Fail2ban on Debian 11

    View 12 Comments

    12 Comments

    1. Atul on November 17, 2020 2:33 pm

      Thanks you so much for great help. It is working.

      Reply
    2. Hari on January 31, 2020 10:37 pm

      Thank you! so much it’s worked..
      Great! Exactly what I want it, I found here.

      Reply
    3. Sunil on September 19, 2019 7:06 pm

      Very nice web site.. too much knowledge data.
      Please could help one .cer to pfx converstion method

      Reply
    4. mohammed on March 29, 2019 9:49 am

      Hi Rahul,
      I have used the same command to convert a pks cert to a pem cert when I did this I noticed that the RSA key was showing as unencrypted i.e. when I open the pem in notepad the rsa key does not say “Encrypted” is this normal behaviour when converting in openssl? I need to have a certificate with the private key without hte passphrase so do I still need to remove the passphrase or was this done as part of the conversion process in openssl?

      Reply
    5. Joe on May 4, 2018 2:33 pm

      Perfect, thanks for the help!

      Reply
    6. Jerry on April 27, 2018 8:57 am

      a silly question. how do I find the pfx file? or normally where it’s located in a Linux Redhat?

      Reply
    7. Paul on March 15, 2018 5:04 pm

      Thank you for this. I looked all over for this exact information. A nice clean page, good info. You helped me get past a major hurdle.

      Thanks

      Reply
    8. Venkatesh on December 13, 2017 8:46 pm

      Perfect

      Reply
    9. Britney on December 4, 2017 3:29 pm

      Thanks, worked great.

      Reply
    10. Sandeep on November 23, 2017 2:15 am

      Thanks, it worked

      Reply
    11. sudhir on November 6, 2017 2:33 pm

      Thankyou it worked

      Reply
    12. Việt Hùng on July 25, 2017 1:17 am

      Thank you. I need it.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Configure Postfix to Use Gmail SMTP on Ubuntu & Debian
    • PHP Arrays: A Beginner’s Guide
    • Deploying Flask Application on Ubuntu (Apache+WSGI)
    • OpenSSL: Working with SSL Certificates, Private Keys and CSRs
    • How to Create and Read List in Python
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.