Archived Forum Post

Index of archived forum posts

Question:

Certificate Private key problem in Windows XP and Native X509Certificate

Jul 08 '15 at 05:51

I have .net third-party webbrowser that need a X509Certificate object.

I load pfx data from my db using Chilkat. I test in Windows 7 and Windows 10 and works well. In Windows XP Im Having problems. I do some test. Native code:

string file = "C:\certificates\someClientCert.pfx";
string pass = "1234"

X509Certificate2 certificate = new X509Certificate2(file, pass);
//This Show the correct client certificate name
MessageBox.Show(certificate.Subject);
//True
MessageBox.Show(certificate.HasPrivateKey().ToString());

Now with Chilkat intermediary(i test memory pfx data functions too):

string file = @"C:\certificates\someClientCert.pfx";
string pass = "1234"
var pfxFile = Path.Combine(Path.GetTempPath(), "CQ-" + Guid.NewGuid() + ".pfx");
var cert = new ChilkatCert();
cert.LoadPfxFile(file, pass);
//Same correct name certificate
MessageBox.Show(cert.SubjectCN);
//True
MessageBox.Show(cert.HasPrivateKey().ToString());
//Now exports
cert.ExportToPfxFile(pfxFile, pass, 1);
//Load exported pfx with native .net code
 X509Certificate2 certificate = new X509Certificate2(pfxFile, pass);
//This Show the correct client certificate name
MessageBox.Show(certificate.Subject);
//False. Here the error, no private key. Same code and same client certificate, in Windows 7 and Windows 10 shows True. And third party browser load well.
MessageBox.Show(certificate.HasPrivateKey().ToString());

I test reopening with Chilkat the exported cert and has private key. If I pass exported certificate to ChilkatHttp, works ok. Navigating same URL with browser control and native x509certificate, fails in XP but not in 7 or 10.