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

C# X509Certificates.X509Certificate类代码示例

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

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



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

示例1: OnValidationCallback

        public bool OnValidationCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
        {
            if (errors.ToString() != "None")
            {
                MessageBox.Show("Please click yes on the next dialog box.\nThis will allow us to install the Net7 certificate.", "Certificate Install",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                try
                {
                    X509Store Certificate = new X509Store(StoreName.Root);

                    X509Certificate2 cert2 = new X509Certificate2(cert);

                    Certificate.Open(OpenFlags.ReadWrite);

                    // Add Certificate
                    Certificate.Add(cert2);
                    Certificate.Close();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Error installing certificate: " + e.ToString());
                }
            }
            else
            {
                MessageBox.Show("Certificate is installed!");
            }

            // Remove this message
            ServicePointManager.ServerCertificateValidationCallback = null;

            return true;
        }
开发者ID:RavenB,项目名称:Earth-and-Beyond-server,代码行数:34,代码来源:FormMain.cs


示例2: NfeRetRecepcao2

 public NfeRetRecepcao2(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap12;
     Url = url;
     Timeout = timeOut;
     ClientCertificates.Add(certificado);
 }
开发者ID:carloscds,项目名称:Zeus.Net.NFe.NFCe,代码行数:7,代码来源:NfeRetRecepcao2.cs


示例3: Validate

        /// <summary>
        /// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication.
        /// </summary>
        /// <param name="sender">An object that contains state information for this validation.</param>
        /// <param name="certificate">The certificate used to authenticate the remote party.</param>
        /// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param>
        /// <param name="sslPolicyErrors">One or more errors associated with the remote certificate.</param>
        /// <returns>A Boolean value that determines whether the specified certificate is accepted for authentication.</returns>
        public bool Validate(object sender, X509Certificate certificate, [NotNull] X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors != SslPolicyErrors.None)
            {
                return false;
            }

            if (chain.ChainElements.Count < 2)
            {
                // Self signed.
                return false;
            }

            foreach (var chainElement in chain.ChainElements)
            {
                string subjectKeyIdentifier = GetSubjectKeyIdentifier(chainElement.Certificate);
                if (string.IsNullOrWhiteSpace(subjectKeyIdentifier))
                {
                    continue;
                }

                if (_validSubjectKeyIdentifiers.Contains(subjectKeyIdentifier))
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:pengweiqhca,项目名称:Security,代码行数:37,代码来源:CertificateSubjectKeyIdentifierValidator.cs


示例4: HttpListenerBase

        /// <summary>
        /// Initializes a new instance of the <see cref="HttpListenerBase"/> class.
        /// </summary>
        /// <param name="address">IP Address to accept connections on</param>
        /// <param name="port">TCP Port to listen on, default HTTPS port is 443</param>
        /// <param name="factory">Factory used to create <see cref="IHttpClientContext"/>es.</param>
        /// <param name="certificate">Certificate to use</param>
        protected HttpListenerBase(IPAddress address, int port, IHttpContextFactory factory, X509Certificate certificate)
            : this(address, port, factory)
        {
            Check.Require(certificate, "certificate");

            _certificate = certificate;
        }
开发者ID:kf6kjg,项目名称:halcyon,代码行数:14,代码来源:HttpListenerBase.cs


示例5: SafeFreeCredentials

        public SafeFreeCredentials(X509Certificate certificate, SslProtocols protocols, EncryptionPolicy policy)
            : base(IntPtr.Zero, true)
        {
            Debug.Assert(
                certificate == null || certificate is X509Certificate2,
                "Only X509Certificate2 certificates are supported at this time");

            X509Certificate2 cert = (X509Certificate2)certificate;

            if (cert != null)
            {
                Debug.Assert(cert.HasPrivateKey, "cert.HasPrivateKey");

                using (RSAOpenSsl rsa = (RSAOpenSsl)cert.GetRSAPrivateKey())
                {
                    if (rsa != null)
                    {
                        _certKeyHandle = rsa.DuplicateKeyHandle();
                        Interop.libcrypto.CheckValidOpenSslHandle(_certKeyHandle);
                    }
                }

                // TODO (3390): Add support for ECDSA.

                Debug.Assert(_certKeyHandle != null, "Failed to extract a private key handle");

                _certHandle = Interop.libcrypto.X509_dup(cert.Handle);
                Interop.libcrypto.CheckValidOpenSslHandle(_certHandle);
            }

            _protocols = protocols;
            _policy = policy;
        }
开发者ID:shrutigarg,项目名称:corefx,代码行数:33,代码来源:SecuritySafeHandles.cs


示例6: ValidateServerCertficate

		public bool ValidateServerCertficate (object sender, X509Certificate receivedCertificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
		{
			bool validRequest = true;

//			var enumerator = chain.ChainPolicy.ExtraStore.GetEnumerator();
//
//			while (enumerator.MoveNext ()) {
//				var pem = ExportToPEM (loop.Current);
//			}
//
			if (receivedCertificate.Subject.IndexOf (".xamarin.com", 0, StringComparison.CurrentCultureIgnoreCase) == -1) { //not a request to an Xamarin server so verify certificate
				//This is not an https request for Xamarin Insights

				if (originalRootCertificate == null) {
					validRequest = false;
				} else {
					//check if certificate chain contains original root certificate
					validRequest = chain.ChainPolicy.ExtraStore.Contains (originalRootCertificate);
				}
			}

			if (!validRequest) {
				EventHandler handler = CertificateMismatchFound;
				if (handler != null) {
					handler (this, null);
				}
			}

			return validRequest;
		}
开发者ID:RoyStobbelaar,项目名称:MedewerkerTemp,代码行数:30,代码来源:SslValidator.cs


示例7: SslTransportHandler

 public SslTransportHandler(ITransportLayerHandler next, X509Certificate serverCertificate)
 {
     _next = next;
     _serverCertificate = serverCertificate;
     _inputStream = new InputStream(this);
     next.Callback = this;
 }
开发者ID:JuergenGutsch,项目名称:Nowin,代码行数:7,代码来源:SslTransportHandler.cs


示例8: AcceptNetworkStreamAsync

        /// <summary>
        /// Wait until a network stream is trying to connect, and return the accepted stream.
        /// </summary>
        /// <param name="certificateName">Certificate name of authenticated connections.</param>
        /// <param name="noDelay">No delay?</param>
        /// <param name="token">Cancellation token.</param>
        /// <returns>Connected network stream.</returns>
        public async Task<INetworkStream> AcceptNetworkStreamAsync(
            string certificateName,
            bool noDelay,
            CancellationToken token)
        {
            try
            {
                var awaiter =
                    await
                    Task.WhenAny(this.listener.AcceptTcpClientAsync(), Task.Delay(-1, token)).ConfigureAwait(false);

                var tcpClientTask = awaiter as Task<TcpClient>;
                if (tcpClientTask != null)
                {
                    var tcpClient = tcpClientTask.Result;
                    tcpClient.NoDelay = noDelay;

                    if (!string.IsNullOrEmpty(certificateName) && this.certificate == null)
                    {
                        this.certificate = GetX509Certificate(certificateName);
                    }

                    return new DesktopNetworkStream(tcpClient, this.certificate);
                }

                return null;
            }
            catch (TaskCanceledException)
            {
                return null;
            }
        }
开发者ID:gustavosaita,项目名称:fo-dicom,代码行数:39,代码来源:DesktopNetworkListener.cs


示例9: NfeInutilizacao

 public NfeInutilizacao(string url, X509Certificate certificado, int timeOut)
 {
     SoapVersion = SoapProtocolVersion.Soap11;
     Url = url;
     Timeout = timeOut;
     ClientCertificates.Add(certificado);
 }
开发者ID:mrbrunor,项目名称:Zeus.Net.NFe.NFCe,代码行数:7,代码来源:NfeInutilizacao.cs


示例10: Certificate

 public Certificate(string filename)
 {
     this.keys = "";
     this.generatedCSR = "";
     this.cert = new System.Security.Cryptography.X509Certificates.X509Certificate(filename);
     this.path = System.IO.Path.GetTempPath() + "KBW";
 }
开发者ID:nicholaspaun,项目名称:Kalkulator1,代码行数:7,代码来源:Certificate.cs


示例11: ConfigureCertificates

		private void ConfigureCertificates()
		{
			_certificate = _appleSettings.Certificate;

			_certificates = new X509CertificateCollection();

			if (_appleSettings.AddLocalAndMachineCertificateStores)
			{
				var store = new X509Store(StoreLocation.LocalMachine);
				_certificates.AddRange(store.Certificates);

				store = new X509Store(StoreLocation.CurrentUser);
				_certificates.AddRange(store.Certificates);
			}

			_certificates.Add(_certificate);

			if (_appleSettings.AdditionalCertificates != null)
			{
				foreach (var additionalCertificate in _appleSettings.AdditionalCertificates)
				{
					_certificates.Add(additionalCertificate);
				}
			}
		}
开发者ID:greg84,项目名称:PushSharp,代码行数:25,代码来源:ApplePushChannel.cs


示例12: OnValidateCertificate

 static bool OnValidateCertificate (
     object sender, X509Certificate certificate,
     X509Chain chain,
     SslPolicyErrors sslPolicyErrors)
 {
     return true;
 }
开发者ID:puncsky,项目名称:DrunkAudible,代码行数:7,代码来源:WebServiceClient.cs


示例13: processClient

        private void processClient(TcpClient client)
        {
            X509Certificate certificate = new X509Certificate("..\\..\\..\\Certificate\\Certificate.pfx", "KTYy77216");
            // SslStream; leaveInnerStreamOpen = false;
            SslStream stream = new SslStream(client.GetStream(), false);
            try
            {
                // clientCertificateRequired = false
                // checkCertificateRevocation = true;
                stream.AuthenticateAsServer(certificate, false, SslProtocols.Tls, true);
                Console.WriteLine("Waiting for client message ...");

                // Read a message from the client
                string input = readMessage(stream);
                Console.WriteLine("Received: {0}", input);

                // Write a message to the client
                byte[] message = Encoding.UTF8.GetBytes("Hello client, this is a message from the server :)<EOF>");
                Console.WriteLine("Sending message to client ...");
                stream.Write(message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                stream.Close();
                client.Close();
                return;
            }
            finally
            {
                stream.Close();
                client.Close();
            }
        }
开发者ID:bemk,项目名称:rhc,代码行数:34,代码来源:SslTcpServer.cs


示例14: Validate

        /// <summary>
        /// Validates at least one SPKI hash is known.
        /// </summary>
        /// <param name="sender">An object that contains state information for this validation.</param>
        /// <param name="certificate">The certificate used to authenticate the remote party.</param>
        /// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param>
        /// <param name="sslPolicyErrors">One or more errors associated with the remote certificate.</param>
        /// <returns>A Boolean value that determines whether the specified certificate is accepted for authentication.</returns>
        public bool Validate(object sender, X509Certificate certificate, [NotNull] X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors != SslPolicyErrors.None)
            {
                return false;
            }

            if (chain.ChainElements.Count < 2)
            {
                return false;
            }

            using (HashAlgorithm algorithm = CreateHashAlgorithm())
            {
                foreach (var chainElement in chain.ChainElements)
                {
                    X509Certificate2 chainedCertificate = chainElement.Certificate;
                    string base64Spki = Convert.ToBase64String(algorithm.ComputeHash(ExtractSpkiBlob(chainedCertificate)));
                    if (_validBase64EncodedSubjectPublicKeyInfoHashes.Contains(base64Spki))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:jmloeffler,项目名称:Security,代码行数:35,代码来源:CertificateSubjectPublicKeyInfoValidator.cs


示例15: GetRawData

        static byte[] GetRawData(X509Certificate certificate)
        {
            if (certificate == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("certificate");

            return certificate.GetRawCertData();
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:X509RawDataKeyIdentifierClause.cs


示例16: CipherSuiteSelector

        public CipherSuiteSelector(X509Certificate cert)
        {
            KeyExchangeAlgorithm[] keyExchanges;
            string algo_oid = cert.GetKeyAlgorithm ();
            if (algo_oid == "1.2.840.10045.2.1") {
                keyExchanges = new KeyExchangeAlgorithm[] {
                    KeyExchangeAlgorithm.DH_anon,
                    KeyExchangeAlgorithm.ECDH_anon,
                    KeyExchangeAlgorithm.ECDH_ECDSA,
                    KeyExchangeAlgorithm.ECDHE_ECDSA
                };
            } else if (algo_oid == "1.2.840.10040.4.1") {
                keyExchanges = new KeyExchangeAlgorithm[] {
                    KeyExchangeAlgorithm.DH_anon,
                    KeyExchangeAlgorithm.DH_DSS,
                    KeyExchangeAlgorithm.DHE_DSS,
                    KeyExchangeAlgorithm.ECDH_anon
                };
            } else if (algo_oid == "1.2.840.113549.1.1.1") {
                keyExchanges = new KeyExchangeAlgorithm[] {
                    KeyExchangeAlgorithm.DH_anon,
                    KeyExchangeAlgorithm.DH_RSA,
                    KeyExchangeAlgorithm.DHE_RSA,
                    KeyExchangeAlgorithm.ECDH_anon,
                    KeyExchangeAlgorithm.ECDH_RSA,
                    KeyExchangeAlgorithm.ECDHE_RSA,
                    KeyExchangeAlgorithm.RSA
                };
            } else {
                throw new NotSupportedException ();
            }

            _supports = SupportedCipherSuites.FilterKeyExchange (keyExchanges);
        }
开发者ID:kazuki,项目名称:opencrypto-tls,代码行数:34,代码来源:CipherSuiteSelector.cs


示例17: RemoveCertValidate

 bool RemoveCertValidate(object sender, X509Certificate cert,
     X509Chain chain, System.Net.Security.SslPolicyErrors error)
 {
     if (currentPolicy.subjectName == subjectName)
         return true;
     return false;
 }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:7,代码来源:Program.cs


示例18: CheckCertificateEventArgs

 /// <summary>
 /// Initializes a new instance of the <see cref="CheckCertificateEventArgs"/> class.
 /// </summary>
 /// <param name="certificate">The certificate.</param>
 /// <param name="chain">The chain.</param>
 /// <param name="sslpolicyerrors">The sslpolicyerrors.</param>
 public CheckCertificateEventArgs(X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
 {
     Certificate = certificate;
     Chain = chain;
     Sslpolicyerrors = sslpolicyerrors;
     IsValid = true;
 }
开发者ID:modulexcite,项目名称:FTP,代码行数:13,代码来源:CheckCertificateEventArgs.cs


示例19: SecureTcpServer

        public SecureTcpServer(int listenPort, X509Certificate serverCertificate,
            SecureConnectionResultsCallback callback,
            RemoteCertificateValidationCallback certValidationCallback)
        {
            if (listenPort < 0 || listenPort > UInt16.MaxValue)
                throw new ArgumentOutOfRangeException("listenPort");

            if (serverCertificate == null)
                throw new ArgumentNullException("serverCertificate");

            if (callback == null)
                throw new ArgumentNullException("callback");

            onAcceptConnection = new AsyncCallback(OnAcceptConnection);
            onAuthenticateAsServer = new AsyncCallback(OnAuthenticateAsServer);

            this.serverCert = serverCertificate;
            this.certValidationCallback = certValidationCallback;
            this.connectionCallback = callback;
            this.listenPort = listenPort;
            this.disposed = 0;
            this.checkCertifcateRevocation = false;
            this.clientCertificateRequired = false;
            this.sslProtocols = SslProtocols.Default;
        }
开发者ID:BGCX262,项目名称:zynchronyze-svn-to-git,代码行数:25,代码来源:SecureTcpServer.cs


示例20: RunServer

        public static void RunServer(string certificate)
        {   
            //The certificate parameter specifies the name of the file containing the machine certificate

            serverCertificate = X509Certificate.CreateFromCertFile(certificate);

        }
开发者ID:Rafael-Miceli,项目名称:ProjectStudiesCert70-536,代码行数:7,代码来源:Program.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# X509Certificates.X509Certificate2类代码示例发布时间:2022-05-26
下一篇:
C# X509Certificates.X500DistinguishedName类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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