Alik Levin's

Clarity, Technology, and Solving Problems | PracticeThis.com

Different Ways To Get Hold On Certificates - Net FX 1.1, 2.0

Different Ways To Get Hold On Certificates - Net FX 1.1, 2.0

  • Comments 1

Net FX 1.1:

First, one need to export certificate to file (no private keys exported), from

http://msdn2.microsoft.com/en-us/library/aa302408.aspx

// TODO: Replace with a valid path to your certificate
string certPath = @"C:\WSClientCert.cer"

// create an X509Certificate object from the information
// in the certificate export file and add it to the


X509Certificate.CreateFromCertFile(certPath));

Net FX 2.0:

2.0 has new classes to get hold on cert directly from cert store, from http://msdn.microsoft.com/msdnmag/issues/07/03/netsecurity/default.aspx 

 

static X509Certificate2 FindCertificate(
StoreLocation location, StoreName name,
X509FindType findType, string findValue)
{
     X509Store store = new X509Store(name, location);
     try
     {
          // create and open store for read-only access
          store.Open(OpenFlags.ReadOnly);
          // search store
          X509Certificate2Collection col = store.Certificates.Find(findType, findValue,true);


          // return first certificate found
          return col[0];
     }
     // always close the store
     finally { store.Close(); }
}

Enjoy

  • Windows Authentication Identity Flow Through Physical Tiers Identity Flow Through Physical Tiers - Impersonation

Page 1 of 1 (1 items)