当前位置: 首页>>代码示例>>C#>>正文


C# X509Certificate2Collection类代码示例

本文整理汇总了C#中X509Certificate2Collection的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2Collection类的具体用法?C# X509Certificate2Collection怎么用?C# X509Certificate2Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


X509Certificate2Collection类属于命名空间,在下文中一共展示了X509Certificate2Collection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: X509Certificate2CollectionConstructors

        public static void X509Certificate2CollectionConstructors()
        {
            using (X509Certificate2 c1 = new X509Certificate2())
            using (X509Certificate2 c2 = new X509Certificate2())
            using (X509Certificate2 c3 = new X509Certificate2())
            {
                X509Certificate2Collection cc = new X509Certificate2Collection(new X509Certificate2[] { c1, c2, c3 });
                Assert.Equal(3, cc.Count);
                Assert.Same(c1, cc[0]);
                Assert.Same(c2, cc[1]);
                Assert.Same(c3, cc[2]);

                X509Certificate2Collection cc2 = new X509Certificate2Collection(cc);
                Assert.Equal(3, cc2.Count);
                Assert.Same(c1, cc2[0]);
                Assert.Same(c2, cc2[1]);
                Assert.Same(c3, cc2[2]);

                Assert.Throws<ArgumentNullException>(() => new X509Certificate2Collection(new X509Certificate2[] { c1, c2, null, c3 }));

                using (X509Certificate c4 = new X509Certificate())
                {
                    X509Certificate2Collection collection = new X509Certificate2Collection { c1, c2, c3 };
                    ((IList)collection).Add(c4); // Add non-X509Certificate2 object

                    Assert.Throws<InvalidCastException>(() => new X509Certificate2Collection(collection));
                }
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:29,代码来源:CollectionTests.cs

示例2: ImportPkcs7PemBytes_Empty

        public static void ImportPkcs7PemBytes_Empty()
        {
            var collection = new X509Certificate2Collection();
            collection.Import(TestData.Pkcs7EmptyPemBytes);

            Assert.Equal(0, collection.Count);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:CollectionImportTests.cs

示例3: X509Certificate2CollectionEnumerator

        public static void X509Certificate2CollectionEnumerator()
        {
            using (X509Certificate2 c1 = new X509Certificate2())
            using (X509Certificate2 c2 = new X509Certificate2())
            using (X509Certificate2 c3 = new X509Certificate2())
            {
                X509Certificate2Collection cc = new X509Certificate2Collection(new X509Certificate2[] { c1, c2, c3 });
                X509Certificate2Enumerator e = cc.GetEnumerator();
                object ignored;

                // Not started
                Assert.Throws<InvalidOperationException>(() => ignored = e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(c1, e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(c2, e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(c3, e.Current);

                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());

                // ended.
                Assert.Throws<InvalidOperationException>(() => ignored = e.Current);
            }
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:32,代码来源:CollectionTests.cs

示例4: ImportX509PemBytes

        public static void ImportX509PemBytes()
        {
            var collection = new X509Certificate2Collection();
            collection.Import(TestData.MsCertificatePemBytes);

            Assert.Equal(1, collection.Count);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:CollectionImportTests.cs

示例5: ImportX509PemFile

        public static void ImportX509PemFile()
        {
            var collection = new X509Certificate2Collection();
            collection.Import(Path.Combine("TestData", "MS.pem"));

            Assert.Equal(1, collection.Count);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:CollectionImportTests.cs

示例6: ImportedCollection

 public ImportedCollection(X509Certificate2Collection collection)
 {
     // Make an independent copy of the certs to dispose (in case the test mutates the collection after we return.)
     _certs = new X509Certificate2[collection.Count];
     collection.CopyTo(_certs, 0);
     Collection = collection;
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:Cert.cs

示例7: ExportEmpty_Cert

        public static void ExportEmpty_Cert()
        {
            var collection = new X509Certificate2Collection();
            byte[] exported = collection.Export(X509ContentType.Cert);

            Assert.Null(exported);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:CollectionTests.cs

示例8: ImportEmpty_Pkcs12

        public static void ImportEmpty_Pkcs12()
        {
            var collection = new X509Certificate2Collection();

            collection.Import(TestData.EmptyPfx);

            Assert.Equal(0, collection.Count);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:8,代码来源:CollectionImportTests.cs

示例9: ExportEmpty_Pkcs12

        public static void ExportEmpty_Pkcs12()
        {
            var collection = new X509Certificate2Collection();
            byte[] exported = collection.Export(X509ContentType.Pkcs12);

            // The empty PFX is legal, the answer won't be null.
            Assert.NotNull(exported);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:CollectionTests.cs

示例10: ExportMultiplePrivateKeys

        public static void ExportMultiplePrivateKeys()
        {
            var collection = new X509Certificate2Collection();

            try
            {
                collection.Import(Path.Combine("TestData", "DummyTcpServer.pfx"), (string)null, X509KeyStorageFlags.Exportable | Cert.EphemeralIfPossible);
                collection.Import(TestData.PfxData, TestData.PfxDataPassword, X509KeyStorageFlags.Exportable | Cert.EphemeralIfPossible);

                // Pre-condition, we have multiple private keys
                int originalPrivateKeyCount = collection.OfType<X509Certificate2>().Count(c => c.HasPrivateKey);
                Assert.Equal(2, originalPrivateKeyCount);

                // Export, re-import.
                byte[] exported;

                try
                {
                    exported = collection.Export(X509ContentType.Pkcs12);
                }
                catch (PlatformNotSupportedException)
                {
                    // [ActiveIssue(2743, TestPlatforms.AnyUnix)]
                    // Our Unix builds can't export more than one private key in a single PFX, so this is
                    // their exit point.
                    //
                    // If Windows gets here, or any exception other than PlatformNotSupportedException is raised,
                    // let that fail the test.
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        throw;
                    }

                    return;
                }

                // As the other half of issue 2743, if we make it this far we better be Windows (or remove the catch
                // above)
                Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "RuntimeInformation.IsOSPlatform(OSPlatform.Windows)");

                using (ImportedCollection ic = Cert.Import(exported))
                {
                    X509Certificate2Collection importedCollection = ic.Collection;

                    Assert.Equal(collection.Count, importedCollection.Count);

                    int importedPrivateKeyCount = importedCollection.OfType<X509Certificate2>().Count(c => c.HasPrivateKey);
                    Assert.Equal(originalPrivateKeyCount, importedPrivateKeyCount);
                }
            }
            finally
            {
                foreach (X509Certificate2 cert in collection)
                {
                    cert.Dispose();
                }
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:58,代码来源:CollectionTests.cs

示例11: AddDoesNotClone

        public static void AddDoesNotClone()
        {
            using (X509Certificate2 c1 = new X509Certificate2())
            {
                X509Certificate2Collection coll = new X509Certificate2Collection();
                coll.Add(c1);

                Assert.Same(c1, coll[0]);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:CollectionTests.cs

示例12: AddCertificatesToStore

	static void AddCertificatesToStore(string cert , string password , StoreLocation loc)
		{
		//Import the pfx certificates
		X509Certificate2Collection certificates = new X509Certificate2Collection() ; 
		certificates.Import( cert , password , X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
		
		//Add the Certificate
		X509Store store = new X509Store( storeName , loc) ; // , "Cool Store" ) ; 
		store.Open( OpenFlags.ReadWrite ) ;
		store.AddRange( certificates ) ; 			
		store.Close() ; 
		}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:12,代码来源:storebug.cs

示例13: X509CertificateCollectionsProperties

        public static void X509CertificateCollectionsProperties()
        {
            IList ilist = new X509CertificateCollection();
            Assert.False(ilist.IsSynchronized);
            Assert.False(ilist.IsFixedSize);
            Assert.False(ilist.IsReadOnly);

            ilist = new X509Certificate2Collection();
            Assert.False(ilist.IsSynchronized);
            Assert.False(ilist.IsFixedSize);
            Assert.False(ilist.IsReadOnly);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:12,代码来源:CollectionTests.cs

示例14: BuildChainExtraStoreUntrustedRoot

        public static void BuildChainExtraStoreUntrustedRoot()
        {
            using (var testCert = new X509Certificate2(Path.Combine("TestData", "test.pfx"), TestData.ChainPfxPassword))
            {
                X509Certificate2Collection collection = new X509Certificate2Collection();
                collection.Import(Path.Combine("TestData", "test.pfx"), TestData.ChainPfxPassword, X509KeyStorageFlags.DefaultKeySet);

                X509Chain chain = new X509Chain();
                chain.ChainPolicy.ExtraStore.AddRange(collection);
                chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
                chain.ChainPolicy.VerificationTime = new DateTime(2015, 9, 22, 12, 25, 0);

                bool valid = chain.Build(testCert);

                Assert.False(valid);
                Assert.Contains(chain.ChainStatus, s => s.Status == X509ChainStatusFlags.UntrustedRoot);
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:18,代码来源:ChainTests.cs

示例15: MultipleImport

        public static void MultipleImport()
        {
            var collection = new X509Certificate2Collection();

            collection.Import(Path.Combine("TestData", "DummyTcpServer.pfx"), null, default(X509KeyStorageFlags));
            collection.Import(TestData.PfxData, TestData.PfxDataPassword, default(X509KeyStorageFlags));

            Assert.Equal(3, collection.Count);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:9,代码来源:CollectionTests.cs


注:本文中的X509Certificate2Collection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。