Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Exporting a certificate's private key to file (pem, cert, pfx)

$
0
0

I am doing some work with certificates and need to export a certificate (.cer) and private key (.pem or .key) to separate files. I can use theExport-PFXCertifiacte cmdlet to get a .pfx file with a password that contains both the certificate and the key, but I need to have the key as a separate file. Everything that I've found explains how to open the pfx and save the key with OpenSSL, XCA or KeyStore Explorer, but I am looking for a way to do this with just Powershell.

I am getting the .cer file itself through Export-Certificate which is working well, it's just getting the key that I need help with. If there isn't a way to export it through a cmdlet, I could write it to a text file, but I'm not sure how to get the certificate's private key into the text file the correct way. The pem key file would look something like this:

"----BEGIN RSA PRIVATE KEY----""Proc-Type: " + $procType"DEK-Info: " + $DEKInfo
$privateKey"-----END RSA PRIVATE KEY-----"

I'm using Windows Server 2012 R2 & WMF 5.0. Any suggestions?



Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>