Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

November 30, 2005

ASP.NET Sample Listing Certificates available to the ASPNET Process.

This C# ASP.NET Example demonstrates how to use the Chilkat .NET certificate classes (CreateCS, CertStore, and Cert) to list the certificates available to an ASP.NET program.

<font face=courier size=2>
		// What certificates are visible to this process?  This program lists them…
		// The ASP.NET process will probably be running under the ASPNET account.
		// You can verify by checking the System.Environment.UserName property.
	
		Chilkat.CreateCS ccs = new Chilkat.CreateCS();
	
		// First check the Current User Certificate Store.
		// These are certificates specific to the current logged-on user.
		TextBox4.Text = "Current User Certificate Store…….\r\n";
	
		Chilkat.CertStore cs = ccs.OpenCurrentUserStore();
		int i;
		int n = cs.NumCertificates;
		if (n == 0) TextBox4.Text = TextBox4.Text + "No Certificates in Current User Store.\r\n";
		for (i=0; i<n ; i++)
		{
		    Chilkat.Cert cert = cs.GetCertificate(i);
		    TextBox4.Text = TextBox4.Text + cert.SubjectDN + "\r\n";
	
		    // Do we have the private key?
		    // The private key is required for creating a digital signature
		    // or decrypting.  It is not required for signature verification
		    // or encrypting.
		    if (cert.HasPrivateKey())
		    {
			TextBox4.Text = TextBox4.Text + "  ++ HAS Private Key\r\n";
		    }
		    else
		    {
			TextBox4.Text = TextBox4.Text + "  — NO Private Key\r\n";
		    }
		}	
	
		TextBox4.Text = TextBox4.Text + "Local Machine Certificate Store…….\r\n";
	
		// What’s in the local system (i.e. local machine) certificate store?
		cs = ccs.OpenLocalSystemStore();
		n = cs.NumCertificates;
		if (n == 0) TextBox4.Text = TextBox4.Text + "No Certificates in Local Machine Store.\r\n";
		for (i=0; i<n; i++)
		{
		    Chilkat.Cert cert = cs.GetCertificate(i);
		    TextBox4.Text = TextBox4.Text + cert.SubjectDN + "\r\n";
	
		    // Do we have the private key?
		    if (cert.HasPrivateKey())
		    {
			TextBox4.Text = TextBox4.Text + "  ++ HAS Private Key\r\n";
		    }
		    else
		    {
			TextBox4.Text = TextBox4.Text + "  — NO Private Key\r\n";
		    }
		}
</font>


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.