[Mono-list] Mono-2.10.2 System.Security.Cryptography.X509Certificates
will.omalley
omalley.william at gmail.com
Thu Dec 22 12:19:48 EST 2011
The following code does not work correctly.
I have several certificates in AuthRoot, CA, My and TrustedPublisher.
However, no results get printed to the screen for any store and the
certificate count is always 0
Full Console Program -- Mono-2.10.2
<CODE>
using System;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace MonoConsoleProject
{
class MainClass
{
private static X509Store certStore;
public static void Main (string[] args)
{
certStore = new X509Store(StoreName.AddressBook,
StoreLocation.CurrentUser);
FindCertInStore(certStore, "StoreName.AddressBook,
StoreLocation.CurrentUser");
//
certStore = new X509Store(StoreName.AuthRoot,
StoreLocation.CurrentUser);
FindCertInStore(certStore, "StoreName.AuthRoot,
StoreLocation.CurrentUser");
//
certStore = new X509Store(StoreName.CertificateAuthority,
StoreLocation.CurrentUser);
FindCertInStore(certStore, "StoreName.CertificateAuthority,
StoreLocation.CurrentUser");
//
certStore = new X509Store(StoreName.Disallowed,
StoreLocation.CurrentUser);
FindCertInStore(certStore, "StoreName.Disallowed,
StoreLocation.CurrentUser");
//
certStore = new X509Store(StoreName.My,
StoreLocation.CurrentUser);
FindCertInStore(certStore, "StoreName.My,
StoreLocation.CurrentUser");
//
certStore = new X509Store(StoreName.Root,
StoreLocation.CurrentUser);
FindCertInStore(certStore, "StoreName.Root,
StoreLocation.CurrentUser");
//
certStore = new X509Store(StoreName.TrustedPeople,
StoreLocation.CurrentUser);
FindCertInStore(certStore, "StoreName.TrustedPeople,
StoreLocation.CurrentUser");
//
certStore = new X509Store(StoreName.TrustedPublisher,
StoreLocation.CurrentUser);
FindCertInStore(certStore, "StoreName.TrustedPublisher,
StoreLocation.CurrentUser");
//
}
private static void FindCertInStore(X509Store store, string
storeName)
{
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("Listing certs in store: " + storeName);
Console.WriteLine("Number of certs in store: " +
store.Certificates.Count.ToString());
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 cert in store.Certificates)
{
string certName = cert.Subject.ToString();
Console.WriteLine("Certificate: " + certName);
if (certName.IndexOf("LynxRootCA") > -1 ||
certName.IndexOf("localhost") > -1)
{
Console.WriteLine("Found Certificate!! " +
System.DateTime.Now.ToString());
}
}
store.Close();
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine();
Console.WriteLine();
}
}
}
</CODE>
--
View this message in context: http://mono.1490590.n4.nabble.com/Mono-2-10-2-System-Security-Cryptography-X509Certificates-tp4226001p4226001.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list