private X509Certificate2 GetCertificateFromServiceStore(string thumbprint, string serviceName) { if (!isService && serviceName == null) { return(null); } try { X509Store store; if (serviceName == null) { store = X509ServiceStoreHelper.Open(OpenFlags.ReadOnly); } else { store = X509ServiceStoreHelper.Open(serviceName, OpenFlags.ReadOnly); } using (store) { foreach (var item in store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false)) { return(item); } } } catch { // ignored } return(null); }
public X509Certificate2Collection GetEligiblePasswordEncryptionCertificates(bool needPrivateKey) { X509Certificate2Collection certs = new X509Certificate2Collection(); X509Store store = X509ServiceStoreHelper.Open(Constants.ServiceName, OpenFlags.ReadOnly); GetEligibleCertificates(needPrivateKey, LithnetAccessManagerPasswordEncryptionEku, store, certs); return(certs); }