Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read private key from store

I have an x509 in my local computer store. How do I read in C# ? I need to use get the private key this way

RSACryptoServiceProvider rsa = (RSACryptoServiceProvider).cert.PrivateKey()
like image 366
JohnM Avatar asked Oct 29 '22 22:10

JohnM


1 Answers

This will get you the certificates from the "My" (personal) store.

var store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
var certificate = store.Certificates.Single(c => c.Thumbprint == "Whatever-Your-Thumbprint-Is");    
store.Close();

At that point you will have an X509Certificate2 and you can access the PrivateKey property from it.

like image 134
Yushatak Avatar answered Nov 15 '22 09:11

Yushatak