/// <summary> /// Remove certficates /// </summary> /// <param name="trustList"></param> /// <param name="certificates"></param> /// <returns></returns> public static void Remove(this CertificateTrustList trustList, IEnumerable <X509Certificate2> certificates) { if (certificates == null) { throw new ArgumentNullException(nameof(certificates)); } using (var trustedStore = trustList.OpenStore()) { trustedStore.Remove(certificates); foreach (var cert in certificates) { trustList.TrustedCertificates.Remove(new CertificateIdentifier(cert)); } } }
/// <summary> /// Add to trust list /// </summary> /// <param name="trustList"></param> /// <param name="certificates"></param> /// <param name="noCopy"></param> /// <returns></returns> public static void Add(this CertificateTrustList trustList, IEnumerable <X509Certificate2> certificates, bool noCopy = false) { if (certificates == null) { throw new ArgumentNullException(nameof(certificates)); } using (var trustedStore = trustList.OpenStore()) { trustedStore.Add(certificates, noCopy); foreach (var cert in certificates) { trustList.TrustedCertificates.Add(new CertificateIdentifier( noCopy ? cert : new X509Certificate2(cert))); } } }