Getting Windows Certificate using C# By Serial Number

After installing a certificate in windows store, you need to use it in your code to encrypt or decrypt the message.

Certificate

You can get the serial number of the certificate by double click on the certificate.

X509Store store = new X509Store(StoreLocation.LocalMachine); 
store.Open(OpenFlags.ReadOnly); 
string sn = " put here your certificate serial number "; 
X509Certificate2Collection coll = 
store.Certificates.Find(X509FindType.FindBySerialNumber, sn, true); 
if (coll[0] != null)
   X509Certificate2 myCert = coll[0];
Advertisements

Create Self Signed Certificate in IIS 7

To create a self signed certificate in IIS7 follow these steps:

  1. In Run command, type inetmgr
  2. IISCertificate
  3. After clicking on Server Certifcates, you will see
  4. On right menu, click on Create Self-Signed Certificate
  5. Certificate Name
  6. Select Certificate