Question

I am trying to implement HTTP communication authenticated by client certificate. When sending an HTTP request on "normal" (i.e. not Compact) .NET Framework, it's quite simple:

HttpWebRequest request = ...;
string certificatePath = ...;
string certificatePassword = ...;

request.ClientCertificates.Add(
    new X509Certificate(certificatePath, certificatePassword));                  

However, on Compact Framework 3.5, X509Certificate has only one constructor which accepts byte array and nothing else. I suppose that I should read a certificate file and pass its contents into that byte array, but what about the password? How should I specify it on Compact Framework?

Was it helpful?

Solution

I did not find any way to use X509Certificate and password.

In the end, I've decided to use X509Store and grab certificates from there. This will make deployment a bit more difficult then originally anticipated, but at least it's doable :)

OTHER TIPS

I'm two years late, but I stumbled across this question in my own research.

If you look closely at the documentation's example code, you see that you have to first open the PFX file and then export it before creating another instance of the X509Certificate class.

The way I understood this is as follows: the full .NET Framework API (i.e., on the desktop) takes a password parameter for the class' constructor as an overload. So, using the full framework, you export the certificate's raw data (i.e., without the securing password) using the Export method and then store the resulting byte array into a file. Afterward, you transfer that file to the mobile device, read the file into a byte array and pass that to the X509Certificate constructor on the Compact Framework.

Of course, this is the "raw" way of going about the problem. One has to then take care to secure the data being transferred in some way.

On further reading, exporting the PFX file in this way does not include the private key, though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top