• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# X509CertificateCollection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Main

	static void Main(string[] args)
	{
		string host = "localhost";
		if (args.Length > 0)
			host = args[0];

		SslProtocols protocol = SslProtocols.Tls;
		if (args.Length > 1) {
			switch (args [1].ToUpper ()) {
			case "SSL":
				protocol = SslProtocols.Ssl3;
				break;
			}
		}

		X509CertificateCollection certificates = null;
		if (args.Length > 2) {
			string password = null;
			if (args.Length > 3)
				password = args [3];

			p12 = Mono.Security.X509.PKCS12.LoadFromFile(args [2], password);

			certificates = new X509CertificateCollection ();
			foreach (Mono.Security.X509.X509Certificate cert in p12.Certificates) {
				certificates.Add(new X509Certificate2(args [2], password));
				break;
			}
		}

		TcpClient client = new TcpClient ();
		client.Connect (host, 4433);
 
 		SslStream ssl = new SslStream (client.GetStream(), false, new RemoteCertificateValidationCallback (CertificateValidation), new LocalCertificateSelectionCallback (ClientCertificateSelection));

		ssl.AuthenticateAsClient (host, certificates, protocol, false); 	
		StreamWriter sw = new StreamWriter (ssl, System.Text.Encoding.ASCII);
		sw.WriteLine ("GET /clientcert.aspx{0}", Environment.NewLine);
		sw.Flush ();

		StreamReader sr = new StreamReader (ssl);
		Console.WriteLine (sr.ReadToEnd ());
	}
开发者ID:nlhepler,项目名称:mono,代码行数:43,代码来源:mutual.cs


示例2: BuildX509Chain

		static bool BuildX509Chain (X509CertificateCollection certs, X509Chain chain, ref SslPolicyErrors errors, ref int status11)
		{
#if MOBILE
			return false;
#else
			if (is_macosx)
				return false;

			var leaf = (X509Certificate2)certs [0];

			bool ok;
			try {
				ok = chain.Build (leaf);
				if (!ok)
					errors |= GetErrorsFromChain (chain);
			} catch (Exception e) {
				Console.Error.WriteLine ("ERROR building certificate chain: {0}", e);
				Console.Error.WriteLine ("Please, report this problem to the Mono team");
				errors |= SslPolicyErrors.RemoteCertificateChainErrors;
				ok = false;
			}

			try {
				status11 = GetStatusFromChain (chain);
			} catch {
				status11 = -2146762485; // TRUST_E_FAIL - generic
			}

			return ok;
#endif
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:31,代码来源:SystemCertificateValidator.cs


示例3: TrustEvaluateSsl

		internal static bool TrustEvaluateSsl (X509CertificateCollection collection)
		{
			var certsRawData = new List <byte[]> (collection.Count);
			foreach (var cert in collection)
				certsRawData.Add (cert.GetRawCertData ());
			return trustEvaluateSsl (certsRawData);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:AndroidPlatform.cs


示例4: X509CertificateCollectionEnumerator

        public static void X509CertificateCollectionEnumerator()
        {
            using (X509Certificate2 c1 = new X509Certificate2())
            using (X509Certificate2 c2 = new X509Certificate2())
            using (X509Certificate2 c3 = new X509Certificate2())
            {
                X509CertificateCollection cc = new X509CertificateCollection(new X509Certificate[] { c1, c2, c3 });
                X509CertificateCollection.X509CertificateEnumerator 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


示例5: ProcessAsTls1

		protected override void ProcessAsTls1()
		{
			this.certificates = new X509CertificateCollection();
			
			int readed	= 0;
			int length	= this.ReadInt24();

			while (readed < length)
			{
				// Read certificate length
				int certLength = ReadInt24();

				// Increment readed
				readed += 3;

				if (certLength > 0)
				{
					// Read certificate data
					byte[] buffer = this.ReadBytes(certLength);

					// Create a new X509 Certificate
					X509Certificate certificate = new X509Certificate(buffer);
					certificates.Add(certificate);

					readed += certLength;

					DebugHelper.WriteLine(
						String.Format("Server Certificate {0}", certificates.Count),
						buffer);
				}
			}

			this.validateCertificates(certificates);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:34,代码来源:TlsServerCertificate.cs


示例6: CreateX509Chain

		public static X509Chain CreateX509Chain (X509CertificateCollection certs)
		{
			var chain = new X509Chain ();
			chain.ChainPolicy = new X509ChainPolicy ((X509CertificateCollection)(object)certs);

#if !MOBILE
			chain.ChainPolicy.RevocationMode = revocation_mode;
#endif

			return chain;
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:11,代码来源:SystemCertificateValidator.cs


示例7: Create

		internal static SSPIInterface Create (string hostname, bool serverMode, SchProtocols protocolFlags, X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
		                                           bool remoteCertRequired, bool checkCertName, bool checkCertRevocationStatus, EncryptionPolicy encryptionPolicy,
		                                           LocalCertSelectionCallback certSelectionDelegate, RemoteCertValidationCallback remoteValidationCallback, SSPIConfiguration userConfig)
		{
			if (userConfig.Settings != null && remoteValidationCallback != null)
				throw new InvalidOperationException ();
			var context = userConfig.Provider.CreateTlsContext (
				hostname, serverMode, (TlsProtocols)protocolFlags, serverCertificate, clientCertificates,
				remoteCertRequired, checkCertName, checkCertRevocationStatus,
				(MonoEncryptionPolicy)encryptionPolicy, userConfig.Settings);
			return new SSPIInterface (context, userConfig.EventSink);
		}
开发者ID:razzfazz,项目名称:mono,代码行数:12,代码来源:SSPIWrapper.cs


示例8: 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


示例9: ClientCertificateSelection

	static X509Certificate ClientCertificateSelection (X509CertificateCollection clientCertificates,
		X509Certificate serverCertificate, string targetHost, X509CertificateCollection serverRequestedCertificates)
	{
		Console.WriteLine ("ClientCertificateSelection");
		Console.WriteLine ("\tClient Certificates ({0})", clientCertificates.Count);
		int i = 1;
		foreach (X509Certificate client in clientCertificates)
			Console.WriteLine ("#{0} - {1}", i++, client.ToString (true));
		Console.WriteLine ("\tHost: {0}", targetHost);
		Console.Write ("SERVER {0}", serverCertificate.ToString (true));
		Console.WriteLine ();
		return clientCertificates [0];
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:13,代码来源:mutual.cs


示例10: ClientCertificateSelection

	static X509Certificate ClientCertificateSelection (object sender, string targetHost, X509CertificateCollection clientCertificates,
		X509Certificate serverCertificate, string [] acceptableIssuers)
	{
		Console.WriteLine ("ClientCertificateSelection");
		Console.WriteLine ("\tClient Certificates ({0})", clientCertificates.Count);
		int i = 1;
		foreach (X509Certificate client in clientCertificates)
			Console.WriteLine ("#{0} - {1}", i++, client.ToString (true));
		Console.WriteLine ("\tHost: {0}", targetHost);
		Console.Write ("SERVER {0}", serverCertificate != null ? serverCertificate.ToString (true) : null);
		Console.WriteLine ();
		if (i == 1)
			return null;
		X509Certificate2 cc = new X509Certificate2 (clientCertificates [0]);
		cc.PrivateKey = PrivateKeySelection (cc, targetHost);
		return cc;
	}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:mutual.cs


示例11: Connect

        /// <summary>
        /// Connect to the registry end point
        /// </summary>
        public void Connect()
        {
            var client = new TcpClient(EPP_REGISTRY_COM, PORT);

            stream = new SslStream(client.GetStream(), false, ValidateServerCertificate);

            if (clientCertificate != null)
            {
                var clientCertificates = new X509CertificateCollection {clientCertificate};

                stream.AuthenticateAsClient(EPP_REGISTRY_COM, clientCertificates, SslProtocols.Ssl3, false);
            }
            else
            {
                stream.AuthenticateAsClient(EPP_REGISTRY_COM);
            }

        }
开发者ID:softwareengr,项目名称:EppLib.NET,代码行数:21,代码来源:TcpTransport.cs


示例12: Main

	static void Main(string[] args)
	{
		string host = "localhost";
		if (args.Length > 0)
			host = args[0];

		SecurityProtocolType protocol = SecurityProtocolType.Tls;
		if (args.Length > 1) {
			switch (args [1].ToUpper ()) {
			case "SSL":
				protocol = SecurityProtocolType.Ssl3;
				break;
			}
		}

		X509CertificateCollection certificates = null;
		if (args.Length > 2) {
			string password = null;
			if (args.Length > 3)
				password = args [3];

			p12 = Mono.Security.X509.PKCS12.LoadFromFile(args [2], password);

			certificates = new X509CertificateCollection ();
			foreach (Mono.Security.X509.X509Certificate cert in p12.Certificates) {
				certificates.Add(new X509Certificate(cert.RawData));
			}
		}

		TcpClient client = new TcpClient ();
		client.Connect (host, 4433);
 
 		SslClientStream ssl = new SslClientStream (client.GetStream(), host, false, protocol, certificates);
 		ssl.ServerCertValidationDelegate += new CertificateValidationCallback (CertificateValidation);
 		ssl.ClientCertSelectionDelegate += new CertificateSelectionCallback (ClientCertificateSelection);
 		ssl.PrivateKeyCertSelectionDelegate += new PrivateKeySelectionCallback (PrivateKeySelection);
	
		StreamWriter sw = new StreamWriter (ssl, System.Text.Encoding.ASCII);
		sw.WriteLine ("GET /clientcert.aspx{0}", Environment.NewLine);
		sw.Flush ();

		StreamReader sr = new StreamReader (ssl);
		Console.WriteLine (sr.ReadToEnd ());
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:44,代码来源:mutual.cs


示例13: ProcessAsTls1

		protected override void ProcessAsTls1()
		{
			int bytesRead = 0;
			int length = this.ReadInt24 ();
			this.clientCertificates = new X509CertificateCollection ();
			while (length > bytesRead) {
				int certLength = this.ReadInt24 ();
				bytesRead += certLength + 3;
				byte[] cert = this.ReadBytes (certLength);
				this.clientCertificates.Add (new X509Certificate (cert));
			}

			if (this.clientCertificates.Count > 0) 
			{
				this.validateCertificates (this.clientCertificates);
			} 
			else if ((this.Context as ServerContext).ClientCertificateRequired) 
			{
				throw new TlsException (AlertDescription.NoCertificate);
			}
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:21,代码来源:TlsClientCertificate.cs


示例14: X509CertificateCollectionConstructors

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

                X509CertificateCollection cc2 = new X509CertificateCollection(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 X509CertificateCollection(new X509Certificate[] { c1, c2, null, c3 }));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:21,代码来源:CollectionTests.cs


示例15: Connect

        /// <summary>
        /// Connect to the registry end point
        /// </summary>
        public void Connect(SslProtocols sslProtocols)
        {
            var client = new TcpClient(EPP_REGISTRY_COM, PORT);

            stream = new SslStream(client.GetStream(), false, ValidateServerCertificate)
                     {
                         ReadTimeout = READ_TIMEOUT,
                         WriteTimeout = WRITE_TIMEOUT
                     };

            if (clientCertificate != null)
            {
                var clientCertificates = new X509CertificateCollection {clientCertificate};

                stream.AuthenticateAsClient(EPP_REGISTRY_COM, clientCertificates, sslProtocols, false);
            }
            else
            {
                stream.AuthenticateAsClient(EPP_REGISTRY_COM);
            }

        }
开发者ID:CodeMakerInc,项目名称:EppLib.NET,代码行数:25,代码来源:TcpTransport.cs


示例16: X509CertificateCollectionRemoveAt

        public static void X509CertificateCollectionRemoveAt()
        {
            using (X509Certificate c1 = new X509Certificate())
            using (X509Certificate c2 = new X509Certificate())
            using (X509Certificate c3 = new X509Certificate())
            {
                X509CertificateCollection cc = new X509CertificateCollection(new X509Certificate[] { c1, c2, c3 });

                cc.RemoveAt(0);
                Assert.Equal(2, cc.Count);
                Assert.Same(c2, cc[0]);
                Assert.Same(c3, cc[1]);

                cc.RemoveAt(1);
                Assert.Equal(1, cc.Count);
                Assert.Same(c2, cc[0]);

                cc.RemoveAt(0);
                Assert.Equal(0, cc.Count);


                IList il = new X509CertificateCollection(new X509Certificate[] { c1, c2, c3 });

                il.RemoveAt(0);
                Assert.Equal(2, il.Count);
                Assert.Same(c2, il[0]);
                Assert.Same(c3, il[1]);

                il.RemoveAt(1);
                Assert.Equal(1, il.Count);
                Assert.Same(c2, il[0]);

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


示例17: X509CertificateCollectionRemove

        public static void X509CertificateCollectionRemove()
        {
            using (X509Certificate2 c1 = new X509Certificate2())
            using (X509Certificate2 c2 = new X509Certificate2(TestData.PfxData, TestData.PfxDataPassword))
            {
                X509CertificateCollection cc = new X509CertificateCollection(new X509Certificate[] { c1, c2 });

                cc.Remove(c1);
                Assert.Equal(1, cc.Count);
                Assert.Same(c2, cc[0]);

                cc.Remove(c2);
                Assert.Equal(0, cc.Count);

                Assert.Throws<ArgumentException>(() => cc.Remove(c2));

                IList il = new X509CertificateCollection(new X509Certificate[] { c1, c2 });

                il.Remove(c1);
                Assert.Equal(1, il.Count);
                Assert.Same(c2, il[0]);

                il.Remove(c2);
                Assert.Equal(0, il.Count);

                Assert.Throws<ArgumentException>(() => il.Remove(c2));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:28,代码来源:CollectionTests.cs


示例18: X509CertificateCollectionIndexOf

        public static void X509CertificateCollectionIndexOf()
        {
            using (X509Certificate2 c1 = new X509Certificate2())
            using (X509Certificate2 c2 = new X509Certificate2(TestData.PfxData, TestData.PfxDataPassword))
            {
                X509CertificateCollection cc = new X509CertificateCollection(new X509Certificate[] { c1, c2 });
                Assert.Equal(0, cc.IndexOf(c1));
                Assert.Equal(1, cc.IndexOf(c2));

                IList il = cc;
                Assert.Equal(0, il.IndexOf(c1));
                Assert.Equal(1, il.IndexOf(c2));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:CollectionTests.cs


示例19: X509CertificateCollectionCopyTo

        public static void X509CertificateCollectionCopyTo()
        {
            using (X509Certificate c1 = new X509Certificate())
            using (X509Certificate c2 = new X509Certificate())
            using (X509Certificate c3 = new X509Certificate())
            {
                X509CertificateCollection cc = new X509CertificateCollection(new X509Certificate[] { c1, c2, c3 });

                X509Certificate[] array1 = new X509Certificate[cc.Count];
                cc.CopyTo(array1, 0);

                Assert.Same(c1, array1[0]);
                Assert.Same(c2, array1[1]);
                Assert.Same(c3, array1[2]);

                X509Certificate[] array2 = new X509Certificate[cc.Count];
                ((ICollection)cc).CopyTo(array2, 0);

                Assert.Same(c1, array2[0]);
                Assert.Same(c2, array2[1]);
                Assert.Same(c3, array2[2]);
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:23,代码来源:CollectionTests.cs


示例20: X509CertificateCollectionSyncRoot

 public static void X509CertificateCollectionSyncRoot()
 {
     var cc = new X509CertificateCollection();
     Assert.NotNull(((ICollection)cc).SyncRoot);
     Assert.Same(((ICollection)cc).SyncRoot, ((ICollection)cc).SyncRoot);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:6,代码来源:CollectionTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# X509Chain类代码示例发布时间:2022-05-24
下一篇:
C# X509Certificate2Collection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap