{"id":9496,"date":"2026-03-20T19:25:53","date_gmt":"2026-03-20T19:25:53","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=9496"},"modified":"2026-03-20T19:25:54","modified_gmt":"2026-03-20T19:25:54","slug":"pfx-to-pem-converter-via-powershell-not-openssl","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/pfx-to-pem-converter-via-powershell-not-openssl","title":{"rendered":"PFX to Pem Converter via Powershell not Openssl"},"content":{"rendered":"\n<p>Had an issue getting Legacy OpenSSL working on my PC<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">param(\n    [Parameter(Mandatory = $true)]\n    [string]$PfxPath,\n\n    [Parameter(Mandatory = $true)]\n    [string]$PfxPassword,\n\n    [string]$CertOut = \".\\cert.pem\",\n    [string]$KeyOut  = \".\\key.pem\"\n)\n\n$securePassword = ConvertTo-SecureString $PfxPassword -AsPlainText -Force\n\n$flags = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable `\n    -bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet\n\n$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new(\n    $PfxPath,\n    $securePassword,\n    $flags\n)\n\nif (-not $cert.RawData) {\n    throw \"Failed to load certificate from PFX.\"\n}\n\n$certPem = @(\n    \"-----BEGIN CERTIFICATE-----\"\n    [Convert]::ToBase64String($cert.RawData, [Base64FormattingOptions]::InsertLineBreaks)\n    \"-----END CERTIFICATE-----\"\n) -join \"`n\"\n\nSet-Content -Path $CertOut -Value $certPem\n\n$rsa = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($cert)\n\nif ($rsa) {\n    $keyBytes = $rsa.ExportPkcs8PrivateKey()\n    $keyPem = @(\n        \"-----BEGIN PRIVATE KEY-----\"\n        [Convert]::ToBase64String($keyBytes, [Base64FormattingOptions]::InsertLineBreaks)\n        \"-----END PRIVATE KEY-----\"\n    ) -join \"`n\"\n    Set-Content -Path $KeyOut -Value $keyPem\n    Write-Host \"Wrote $CertOut and $KeyOut (RSA key)\"\n    exit 0\n}\n\n$ecdsa = [System.Security.Cryptography.X509Certificates.ECDsaCertificateExtensions]::GetECDsaPrivateKey($cert)\n\nif ($ecdsa) {\n    $keyBytes = $ecdsa.ExportPkcs8PrivateKey()\n    $keyPem = @(\n        \"-----BEGIN PRIVATE KEY-----\"\n        [Convert]::ToBase64String($keyBytes, [Base64FormattingOptions]::InsertLineBreaks)\n        \"-----END PRIVATE KEY-----\"\n    ) -join \"`n\"\n    Set-Content -Path $KeyOut -Value $keyPem\n    Write-Host \"Wrote $CertOut and $KeyOut (ECDSA key)\"\n    exit 0\n}\n\nthrow \"No exportable RSA or ECDSA private key found in the PFX.\"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Had an issue getting Legacy OpenSSL working on my PC<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9496","post","type-post","status-publish","format-standard","hentry","category-research"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/9496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=9496"}],"version-history":[{"count":1,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/9496\/revisions"}],"predecessor-version":[{"id":9497,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/9496\/revisions\/9497"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=9496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=9496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=9496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}