Search code examples
c#x509certificate2

Use X509Certificate without requiring passphrase


I have a certificate that I need to use in order to access a web service. The problem is that whenever I try to use the X509 certificate it asks for a passphrase (PIN). Is there any way of providing the passphrase directly, without it popping up the same window every time?

I hate this window

The certificate uses a dongle made by Oberthur Technologies, if it's of any help. Here's the code I use to get the certificate:

X509Store store = new X509Store("MY",StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;

if(collection.Count != 0)
    userCert = collection[0]; // everything's ok up to here

And here's where I use the certificate:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(url));
req.ClientCertificates.Add(userCert); // add the certificate I just got
// ...
WebResponse ret = req.GetResponse(); // here's where it asks me for my passphrase

Solution

  • The certificate's private key is stored on the Oberthur token. It is enforcing the user to enter the PIN to gain access to certificates private key. This is by design and cannot be overridden.