Kurt Claeys

DEVITECT.NET

  Home  |   Contact  |   Syndication    |   Login
  127 Posts | 43 Stories | 163 Comments | 13 Trackbacks

News

I'm a .NET architect / developer from Belgium and also trainer in .NET topics.

Kurt CLAEYS

 



view my trainer profile on TrainerExchange.com
 

Join Me at Tech·Ed EMEA Connect for Developers!

View Kurt CLAEYS's profile on LinkedIn


Being ...





 


Working ...


and



Reading ...



Riding ...

Tag Cloud


Article Categories

Archives

Post Categories

Links

 

When testing with X509 certificates it's sometimes hard to refer to the needed key in the certificate store. It is easier to load them from a file. The Certificates MMC snap-in allows you to export the private key to a file with the .pfx extension. This file must be protected by a password which you have to specify in the code that loads this file as the certificate to be used.

Steps to export ...

Code

Here's some code to load this .pfx file and use it as the clientcertificate.  

//using System.ServiceModel; //using System.ServiceModel.Security; //using System.Security.Cryptography.X509Certificates; X509Certificate2 c; c = new X509Certificate2(@"C:\x509\test.pfx", "thepassword"); WSHttpBinding b = new WSHttpBinding(); b.Security.Mode = SecurityMode.Message; b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; EndpointAddress ea = new EndpointAddress(new Uri("http://...:9999/UseCertificate"), EndpointIdentity.CreateDnsIdentity("TestCert1")); ServiceReference.ServiceClient s; s = new ServiceReference.ServiceClient(b, ea); s.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; s.ClientCredentials.ClientCertificate.Certificate = c;
posted on Sunday, September 02, 2007 7:18 AM