Наследование: System.Collections.IEnumerator
Пример #1
0
        public void RemoveRange(X509Certificate2Collection certificates)
        {
            if (certificates == null)
            {
                throw new ArgumentNullException("certificates");
            }
            int num = 0;

            try
            {
                X509Certificate2Enumerator enumerator = certificates.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    X509Certificate2 current = enumerator.Current;
                    this.Remove(current);
                    num++;
                }
            }
            catch
            {
                for (int i = 0; i < num; i++)
                {
                    this.Add(certificates[i]);
                }
                throw;
            }
        }
Пример #2
0
        private X509Certificate2 SelectBestFromCollection(X509Certificate2 child, X509Certificate2Collection c)
        {
            switch (c.Count)
            {
            case 0:
                return(null);

            case 1:
                return(c[0]);

            default:
            {
                X509Certificate2Collection x509Certificate2Collection = c.Find(X509FindType.FindByTimeValid, ChainPolicy.VerificationTime, validOnly: false);
                switch (x509Certificate2Collection.Count)
                {
                case 0:
                    x509Certificate2Collection = c;
                    break;

                case 1:
                    return(x509Certificate2Collection[0]);
                }
                string authorityKeyIdentifier = GetAuthorityKeyIdentifier(child);
                if (string.IsNullOrEmpty(authorityKeyIdentifier))
                {
                    return(x509Certificate2Collection[0]);
                }
                X509Certificate2Enumerator enumerator = x509Certificate2Collection.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    X509Certificate2 current = enumerator.Current;
                    string           subjectKeyIdentifier = GetSubjectKeyIdentifier(current);
                    if (authorityKeyIdentifier == subjectKeyIdentifier)
                    {
                        return(current);
                    }
                }
                return(x509Certificate2Collection[0]);
            }
            }
        }
Пример #3
0
        internal static System.Security.Cryptography.SafeCertStoreHandle ExportToMemoryStore(X509Certificate2Collection collection)
        {
            new StorePermission(StorePermissionFlags.AllFlags).Assert();
            System.Security.Cryptography.SafeCertStoreHandle invalidHandle = System.Security.Cryptography.SafeCertStoreHandle.InvalidHandle;
            invalidHandle = CAPI.CertOpenStore(new IntPtr(2L), 0x10001, IntPtr.Zero, 0x2200, null);
            if ((invalidHandle == null) || invalidHandle.IsInvalid)
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            X509Certificate2Enumerator enumerator = collection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                X509Certificate2 current = enumerator.Current;
                if (!CAPI.CertAddCertificateLinkToStore(invalidHandle, current.CertContext, 4, System.Security.Cryptography.SafeCertContextHandle.InvalidHandle))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }
            }
            return(invalidHandle);
        }