c# - Loading X509Certificate2 certificate chain from store -


i have file (.p12) contains 3 certificates (chained together) password-protected, have installed on store. i'm trying load them code. way load them file this:

 var clientcert = new x509certificate2(@"myfile.p12", "mypassword"); 

how can achieve same result while loading them store?

i've tried:

var computercastore = new x509store(storename.root, storelocation.localmachine);  computercastore.open(openflags.readonly);  var certificates = computercastore.certificates.oftype<x509certificate2>().toli‌​st();  var certfromstore = certificates.single(c => c.thumbprint == thumbprintmerchant); var newcert = new x509certificate2(certfromstore.rawdata, "mypassword"); 

certfromstore should equivalent clientcert, last line what's breaking you.

the rawdata property on x509certificate2 returns der-encoded value certificate, not original file bytes. certificate not have private key, last line strips away. question had mentioned tls exception, , because cert no longer has private key.

if certfromstore.hasprivatekey false, whatever did put certificate store didn't work way think did. it's pretty unusual certificate private key in root store.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -