Installing client certificates in Windows Store XAML applications

I would like to use client certificate authentication in a Windows Store XAML application. Using makecert, I created self-signed CA and client certificates, authentication works in IIS / ASP.NET + browser (IE10, Chrome, etc.) OK. Now I wanted to use it in the Windows Store application, but I don’t know how to install the certificate. I have a cert.pfx file that I imported into IE10. Here is the code that I use to use the HTTP service over SSL.

HttpClientHandler handler = new HttpClientHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Automatic; HttpClient client = new HttpClient(handler); 

Not sure what the difference is between ClientCertificateOption.Automatic and ClientCertificateOption.Manual. When I try to connect, the certificate does not appear on the server, and I get error 401. I assume that the certificate is not in the application certificate store and therefore nothing is sent to the server. How do I install a certificate?

Should I use the CertificateEnrollmentManager.ImportPfxDataAsync () method? if so, how can I convert .pfx to a 'Base64 encoded PFX message' Should pfx contain a private key?

Or maybe I should use the certificate extension as described here: http://msdn.microsoft.com/en-us/library/windows/apps/hh464981.aspx#certificates_extension_content

+6
source share
1 answer

The following code will download the pfx file and create a base64 encoded string that can be used by the ImportPfxDataAsync method:

 StorageFolder packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation; StorageFolder certificateFolder = await packageLocation.GetFolderAsync("Certificates"); StorageFile certificate = await certificateFolder.GetFileAsync("YourCert.pfx"); IBuffer buffer = await Windows.Storage.FileIO.ReadBufferAsync(certificate); string encodedString = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(buffer); 

It is assumed that you place your certificate in the Certificates folder.

Maybe you should take a look at http://www.piotrwalat.net/client-certificate-authentication-in-asp-net-web-api-and-windows-store-apps/ to go through an end-to-end scenario of using client certificates in Windows 8 application to communicate with asp.NET web api.

+6
source

All Articles