Convert Certificate to PEM format from pfx format

I have encountered a situation where I had the pfx certificate but the application I was working on Gittea required PEM format.

So, sharing a simple way on windows platform à how you can achieve that:

I have researched on the Internet and everywhere I have found openSSL approach which I have not find that much straight forward.

As I love Powershell so started searching that someone from the community might have already created something for it.

Here is the module that can do this magic with a simple PowerShell Style command:

Install-Module -Name PSPKI

After installing this module, you can change to the directory where the pfx file is there. (Do not forget to import the module if you are still working in the same window)

Import-Module PSPKI


You can check what all commands are available in this module as I have done below:

Get-Command -Module PSPKI


The command we are interested in is:

Convert-PfxToPem

Let us check its syntax before proceeding to conversion.

Convert-PfxToPem [-InputFile] <FileInfo> [-Password] <SecureString> [-OutputFile] <FileInfo> [[-OutputType]

<String>] [-IncludeChain <SwitchParameter>] [<CommonParameters>]

Convert-PfxToPem [-Certificate] <X509Certificate2> [-OutputFile] <FileInfo> [[-OutputType] <String>]

[-IncludeChain <SwitchParameter>] [<CommonParameters>]

$password = Read-Host “password” -AsSecureString

Convert-PfxToPem -InputFile ‘c:\temp\Vikas Sukhija.pfx’ -Password $password -OutputFile ‘c:\temp\key.pem’

Now if you check the output file folder you will find the key.pem file.


I hope you will find this TIP helpful as I can see many admins will be in the same situation at some point where I was, so want to share it.

 

Thanks for reading …

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

PowerShell Fast Track

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s