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>