Posted By

rengber on 10/29/07


Tagged

Certificates Keystore


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Getting X509 Certificates in and out of the Key Store


 / Published in: C#
 

URL: http://support.microsoft.com/default.aspx?scid=kb;en-us;901183

Generate the Cert: makecert -sy 3 -n "cn=FooCorp" -ss my -sr LocalMachine

Grant Permissions to the Cert: winHttpCertCfg -g -c LOCAL_MACHINE\MY -s "FooCorp" -a "domain\YourMomma"

  1. public static X509Certificate2 GetCert(string thumbprint,
  2. StoreName storeName,
  3. StoreLocation storeLocation)
  4. {
  5. // The following code gets the cert from the keystore
  6. X509Store store = new X509Store(storeName, storeLocation);
  7. store.Open(OpenFlags.ReadOnly);
  8. X509Certificate2Collection certCollection =
  9. store.Certificates.Find(X509FindType.FindByThumbprint,
  10. thumbprint,
  11. false);
  12. X509Certificate2Enumerator enumerator = certCollection.GetEnumerator();
  13. X509Certificate2 cert = null;
  14. while (enumerator.MoveNext())
  15. {
  16. cert = enumerator.Current;
  17. }
  18. return cert;
  19. }

Report this snippet  

You need to login to post a comment.