public override IEnumerable <CertInfo> ScanCertificates() { foreach (var targetPath in TargetPaths) { if (Directory.Exists(targetPath)) { var certFiles = Directory.GetFiles(targetPath, "*.cer", SearchOption.AllDirectories); foreach (var certFile in certFiles) { var cert = new X509Certificate2(); cert.Import(certFile); var certInfo = new CertInfo() { FriendlyName = cert.FriendlyName, Issuer = cert.Issuer, Version = cert.Version, Thumbprint = cert.Thumbprint, StoreLocation = certFile, ExpDate = DateTime.Parse(cert.GetExpirationDateString()), Abstract = cert.ToString() }; yield return(certInfo); } } } }
public override IEnumerable <CertInfo> ScanCertificates() { foreach (StoreLocation loc in Enum.GetValues(typeof(StoreLocation))) { foreach (StoreName n in Enum.GetValues(typeof(StoreName))) { X509Store store = new X509Store(n, loc); store.Open(OpenFlags.ReadOnly); foreach (var storeCertificate in store.Certificates) { var certInfo = new CertInfo() { Subject = storeCertificate.Subject, FriendlyName = storeCertificate.FriendlyName, Issuer = storeCertificate.Issuer, Version = storeCertificate.Version, Thumbprint = storeCertificate.Thumbprint, StoreLocation = loc.ToString(), ExpDate = DateTime.Parse(storeCertificate.GetExpirationDateString()), Abstract = storeCertificate.ToString() }; yield return(certInfo); } store.Close(); } } }