Exporting Windows Certificate
If you are using Windows to manage your certificates, it is possible to extract this certificate as public and private key pair to use it with other services like deviceWISE. This section explains on extracting the Windows certificate using the Windows Certificate Manager (certmgr.msc). To view and export the certificate, do the following:
- Open the Windows Certificate Manager.
- In the Start menu, type certmgr.msc.
The certmgr.msc appears. - Click certmgr.msc
- In the Start menu, type certmgr.msc.
- Find the certificate you want to export (For example: example.com)
- To export the public key, do the following:
- Right-click on example.com and click All Tasks >> Export
Certificate Export Wizard appears. - Click Next.
- Select Base-64 encoded X.509 (.CER)
- Click Next
- Enter a File name for your certificate.
- Browse to select a location for your certificate.
- Click Next.
Completing the Certificate Export Wizard screen appears. - Click Finish.
A confirmation screen appears, acknowledging the export.
- Right-click on example.com and click All Tasks >> Export
- To export the private key, do the following:
- Right-click on example.com and click All Tasks >> Export
Certificate Export Wizard appears. - Click Next.
- Select Personal Information Exchange - PKCS #12(.PFX) and do not change the default selections.
- Click Next
- Enter a File name for your certificate. For example:server.pfx
- Browse to select a location for your certificate.
- Click Next.
Completing the Certificate Export Wizard screen appears. - Click Finish.
A confirmation screen appears, acknowledging the export.
- Right-click on example.com and click All Tasks >> Export
- To convert the PFX file to a private key, do one of the following:
- Using Command Prompt
- Open the command prompt (ensure openssl is in your PATH).
- Extract the private key from the encoded PFX file server.pfx.
openssl pkcs12 -in server.pfx -nocerts -nodes -out key.pem
- Remove the password from the private key key.pem.
openssl rsa -in key.pem -out server.key
The resulting file is your private key.
- Using Powershell
- Use the following script:
$certSubject = Read-Host -Prompt 'Cert Subject' $certificate = Get-ChildItem -Path Cert:\LocalMachine\My\ | Where-Object {$_.Subject -match $certSubject} $password= "@OurPassword1" | ConvertTo-SecureString -AsPlainText -Force Export-PfxCertificate -Cert $certificate -FilePath tempcert.pfx -Password $password openssl pkcs12 -in tempcert.pfx -nocerts -nodes -out key.pem -password pass:@OurPassword1 openssl rsa -in key.pem -out server.key Export-Certificate -Cert $certificate -FilePath tempcert.p7b -Type p7b openssl pkcs7 -inform DER -outform PEM -in tempcert.p7b -print_certs > server.cer Remove-Item tempcert.*
- Use the following script:
- Using Command Prompt