Getting X509 Certificates in and out of the Key Store


/ Published in: C#
Save to your folder(s)

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"


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.