Educational Resource

Export an RSA private key from the Windows Certificate Store

June 5, 2024
4 min read
Expert Content

Published on

June 5, 2024

Exporting an RSA private key from the Windows Certificate Store can be essential for various administrative and security tasks, especially in environments where OpenSSL is not available. This guide aims to provide a clear, step-by-step process for exporting an RSA private key from a machine running Windows. It is important to note that for this procedure to be successful, the certificate in question must have been imported into the Windows Certificate Store with the "Mark the private key as exportable" option enabled. Following this guide will ensure that you can securely and efficiently manage your cryptographic keys without the need for additional software. 

But before diving into the process, please note that this guide will require you to have local administrator rights on the machine.  

 

After confirming this, follow the next steps: 

Steps to export an RSA private key from the Windows Certificate Store Steps to export an RSA private key from the Windows Certificate Store

 

Step 1: Open an elevated PowerShell command prompt 

Step 2: Retrieve the thumbprint of the certificate that you wish to export with the following command. Example if the certificate is in your personal machine certificate store: 

dir cert:\LocalMachine\My 

 

Step 3: Create a certificate object in the PowerShell prompt based on the thumbprint of your certificate with the following command: 

Want to implement these PKI practices?

Get expert guidance on implementing secure PKI solutions for your organization.

Get Expert Help

$cert = Get-ChildItem Cert:\LocalMachine\My | ? {$_.Thumbprint -eq '<THUMBPRINT_OF_CERTIFICATE_FROM_STEP_2>'} 

Step 4: Read the RSA private key in an RSA CNG object: 

$RSACng = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($cert) 

 

Step 5: Read the bytes from the private key: 

$KeyBytes = $RSACng.Key.Export([System.Security.Cryptography.CngKeyBlobFormat]::Pkcs8PrivateBlob)

Step 6: Encode the key bytes in Base64 format: 

$KeyBase64 = [System.Convert]::ToBase64String($KeyBytes, [System.Base64FormattingOptions]::InsertLineBreaks) 

Step 7: Display the private key in PEM format in the PowerShell command prompt: 

$KeyPem = @"  -----BEGIN PRIVATE KEY-----   $KeyBase64   -----END PRIVATE KEY-----   "@   $KeyPem 

 

Conclusion

Successfully exporting an RSA private key from the Windows certificate store is a crucial skill for system administrators and security professionals who need to manage cryptographic keys without relying on external tools such as OpenSSL. By ensuring that the certificate was initially imported with the “Mark private key as exportable” option enabled, you can follow a streamlined process to securely retrieve the private key. This capability not only increases your flexibility in key management, but also reinforces the importance of proper certificate management and configuration from the start. With this guide, you now have the knowledge you need to confidently export RSA private keys when necessary, maintaining the integrity and security of your cryptographic infrastructure. 

Was this helpful?
Back to Education Center

Table of Contents

Keep Learning

Get the latest educational content and PKI insights delivered to your inbox.

By subscribing you accept to receive our communications. You can unsubscribe at any moment.

Related Resources

Evertrust

Sequence 2: Install and configure NGINX for TLS encryption on RHEL/Debian/OpenSUSE

April 22, 2024
1 min

Improve the security of your web server by mastering TLS encryption. Our detailed guide offers practical steps to set up NGINX on different Linux distributions, adding a layer of security to safeguard sensitive web-transmitted data.

Read more
Evertrust How to

Enable Post Quantum Cryptography Support in Web Browsers

April 17, 2024
1 min

Explore the future of post-quantum cryptography and secure key exchange in web communication. Learn how to enable these advanced security features in top browsers like Microsoft Edge and Firefox. Stay ahead with our step-by-step guide.

Read more
Evertrust

Sequence 1: The guide to Installing and configuring Apache Httpd for TLS encryption on RHEL, Debian, OpenSUSE

April 16, 2024
1 min

Explore the optimal process of setting up and securing a web server on Linux distributions like RHEL, Debian, and OpenSUSE. Mastering TLS encryption implementation on Apache Httpd web servers, we provide concise steps for higher data protection.

Read more

Ready to take back control over your certificates?

Talk to our experts and discover how Evertrust can help you implement best practices in PKI and certificate lifecycle management.

Talk to an expert