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

C# X509FindType类代码示例

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

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



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

示例1: GetFindValue

        /// <summary>
        /// Gets the find value.
        /// </summary>
        /// <param name="findType">Type of the find.</param>
        /// <param name="value">The value.</param>
        /// <returns>The find value formated as string.</returns>
        public static string GetFindValue(X509FindType findType, X509Certificate2 value)
        {
            string findValue = null;

            switch (findType)
            {
                case X509FindType.FindBySubjectDistinguishedName:
                    findValue = GetSubjectDistinguishedName(value.SubjectName.Name);
                    break;
                case X509FindType.FindByThumbprint:
                    findValue = value.Thumbprint;
                    break;
                case X509FindType.FindBySubjectName:
                    findValue = value.SubjectName.Name;
                    break;
                case X509FindType.FindBySerialNumber:
                    findValue = value.SerialNumber;
                    break;
                default:
                    findValue = value.ToString(false);
                    break;
            }

            return findValue;
        }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:31,代码来源:X509CertificateHelper.cs


示例2: Load

        public static X509Certificate2 Load(StoreName name, StoreLocation location, X509FindType type, string findValue)
        {
            if (string.IsNullOrWhiteSpace(findValue))
                throw new ArgumentNullException("findValue");
            
            var store = new X509Store(name, location);
            store.Open(OpenFlags.ReadOnly);
            try
            {
                var certificates = store.Certificates.Find(type, findValue, false);

                if (certificates.Count != 1)
                {
                    throw new InvalidOperationException(
                        string.Format(CultureInfo.InvariantCulture,
                        "Finding certificate with [StoreName:{0}, StoreLocation:{1}, X509FindType: {2}, FindValue: {3}] matched {4} certificates. A unique match is required.",
                        name, location, type, findValue, certificates.Count));
                }

                return certificates[0];
            }
            finally
            {
                store.Close();
            }
        }
开发者ID:hallatore,项目名称:ITfoxtec.SAML2,代码行数:26,代码来源:CertificateUtil.cs


示例3: FromStore

 /// <summary>
 /// Will deploy certificate found by find type and find value from the local certificate store, to remote certificate store on server.
 /// </summary>
 /// <param name="findType"></param>
 /// <param name="findValue"></param>
 /// <returns></returns>
 public static IOfferRemoteConfiguration FromStore(this IOfferSslInfrastructure sslInfra, X509FindType findType, string findValue)
 {
     var infraBuilder = ((SslInfrastructureBuilder) sslInfra).InfrastructureBuilder;
     var certOp = new CertificateFromStoreOperation(findType, findValue);
     Configure.Operation(infraBuilder, certOp);
     return infraBuilder;
 }
开发者ID:peteraglen,项目名称:condep-dsl-operations,代码行数:13,代码来源:SslInfrastructureExtensions.cs


示例4: TryResolveCertificate

        internal static bool TryResolveCertificate(StoreName storeName, StoreLocation storeLocation, X509FindType findType, object findValue, out X509Certificate2 certificate)
        {
            X509Store store = new X509Store(storeName, storeLocation);
            store.Open(OpenFlags.ReadOnly);

            certificate = null;
            X509Certificate2Collection certs = null;
            X509Certificate2Collection matches = null;
            try
            {
                certs = store.Certificates;
                matches = certs.Find(findType, findValue, false);

                // Throwing InvalidOperationException here, following WCF precedent. 
                // Might be worth introducing a more specific exception here.
                if (matches.Count == 1)
                {
                    certificate = new X509Certificate2(matches[0]);
                    return true;
                }
            }
            finally
            {
                CryptoHelper.ResetAllCertificates(matches);
                CryptoHelper.ResetAllCertificates(certs);
                store.Close();
            }

            return false;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:30,代码来源:X509Util.cs


示例5: FromStore

 public IOfferInfrastructure FromStore(X509FindType findType, string findValue)
 {
     var certOp = new CertificateFromStoreOperation(findType, findValue);
     var compositeSequence = _infrastructureSequence.NewCompositeSequence(certOp);
     certOp.Configure(new RemoteCompositeBuilder(compositeSequence, _webDeploy));
     return _infrastructureBuilder;
 }
开发者ID:brigs,项目名称:ConDep,代码行数:7,代码来源:SslInfrastructureBuilder.cs


示例6: LocalMachineCertificateFactory

		/// <summary>
		/// Initializes a new instance of the <see cref="LocalMachineCertificateFactory"/> class.
		/// </summary>
		/// <param name="certificateSubject">The certificate subject.</param>
		/// <param name="findType"></param>
		public LocalMachineCertificateFactory(string certificateSubject, X509FindType findType)
		{
			_certificateSubject = certificateSubject;
			_findType = findType;

			ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;
		}
开发者ID:yonglehou,项目名称:DevDefined.OAuth,代码行数:12,代码来源:LocalMachineCertificateFactory.cs


示例7: X509SecurityTokenProvider

        public X509SecurityTokenProvider(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findValue)
        {
            if (findValue == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("findValue");
            }

            X509CertificateStore store = new X509CertificateStore(storeName, storeLocation);
            X509Certificate2Collection certificates = null;
            try
            {
                store.Open(OpenFlags.ReadOnly);
                certificates = store.Find(findType, findValue, false);
                if (certificates.Count < 1)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.CannotFindCert, storeName, storeLocation, findType, findValue)));
                }
                if (certificates.Count > 1)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.FoundMultipleCerts, storeName, storeLocation, findType, findValue)));
                }

                this.certificate = new X509Certificate2(certificates[0]);
            }
            finally
            {
                SecurityUtils.ResetAllCertificates(certificates);
                store.Close();
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:30,代码来源:X509SecurityTokenProvider.cs


示例8: FetchCertificate

		public FetchCertificate(X509FindType criteria, object match)
		{
			Criteria = criteria;
			MatchesValue = match;
			StoreLocation = StoreLocation.LocalMachine;
			StoreName = StoreName.My;
		}
开发者ID:janv8000,项目名称:Windsor,代码行数:7,代码来源:FetchCertificate.cs


示例9: SetCertificate

        public void SetCertificate(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findValue)
        {
            if (findValue == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("findValue");
            }
            ThrowIfImmutable();
            var dotNetCertificate = SecurityUtils.GetCertificateFromStore(storeName, storeLocation, findType, findValue, null);
            IReadOnlyList<Certificate> uwpCertificates;
            try
            {
                uwpCertificates = GetCertificatesFromWinRTStore(dotNetCertificate);
            }
            catch (Exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(SecurityUtils.CreateCertificateLoadException(
                    storeName, storeLocation, findType, findValue, null, 0));
            }

            if (uwpCertificates.Count != 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(SecurityUtils.CreateCertificateLoadException(
                    storeName, storeLocation, findType, findValue, null, uwpCertificates.Count));
            }

            AttachUwpCertificate(dotNetCertificate, uwpCertificates[0]);
            _certificate = dotNetCertificate;
        }
开发者ID:mehtavipul,项目名称:wcf,代码行数:28,代码来源:X509CertificateInitiatorClientCredential.netcore50.cs


示例10: CreateCustom

		/// <summary>
		/// Creates a custom certificate search directive, based on the specified find type and value.
		/// </summary>
		/// <param name="findType"></param>
		/// <param name="findValue"></param>
		/// <returns></returns>
		public static CertificateSearchDirective CreateCustom(X509FindType findType, string findValue)
		{
			return new CertificateSearchDirective
			{
				FindType = findType,
				FindValue = findValue
			};
		}
开发者ID:nhannd,项目名称:Xian,代码行数:14,代码来源:CertificateSearchDirective.cs


示例11: SecurityBehavior

 public SecurityBehavior(ServiceSecurity mode,StoreLocation storeLocation,StoreName storeName,X509FindType findType,string subjectName)
 {
     m_Mode = mode;
      m_StoreLocation = storeLocation;
      m_StoreName = storeName;
      m_FindType = findType;
      m_SubjectName = subjectName;
 }
开发者ID:JMnITup,项目名称:HotelApp,代码行数:8,代码来源:SecurityBehavior.cs


示例12: Find

 private IEnumerable<X509Certificate2> Find(X509FindType findType, string criteria, bool validOnly) {
     try {
         return _storeWrapper.Find(findType, criteria, validOnly);
     } finally {
         if (_storeWrapper != null) {
             _storeWrapper.Close();
         }
     }
 }
开发者ID:amido,项目名称:CertificateRepository,代码行数:9,代码来源:CertificateRepository.cs


示例13: SetCertificate

 public void SetCertificate(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findValue)
 {
     if (findValue == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("findValue");
     }
     ThrowIfImmutable();
     _certificate = SecurityUtils.GetCertificateFromStore(storeName, storeLocation, findType, findValue, null);
 }
开发者ID:mehtavipul,项目名称:wcf,代码行数:9,代码来源:X509CertificateInitiatorClientCredential.CoreCLR.cs


示例14: ConfigureAnonymousMessageSecurity

        public void ConfigureAnonymousMessageSecurity(StoreLocation location,StoreName storeName,X509FindType findType,object findValue)
        {
            Credentials.ServiceCertificate.SetCertificate(location,storeName,findType,findValue);
             Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;

             foreach(ServiceEndpoint endpoint in Description.Endpoints)
             {
            ServiceBusHelper.ConfigureBinding(endpoint.Binding);
             }
        }
开发者ID:JMnITup,项目名称:SMEX,代码行数:10,代码来源:ServiceBusHost.cs


示例15: SetCertificate

		public void SetCertificate (StoreLocation storeLocation,
			StoreName storeName, X509FindType findType,
			object findValue)
		{
#if !MOBILE
			certificate = ConfigUtil.CreateCertificateFrom (storeLocation, storeName, findType, findValue);
#else
			throw new NotImplementedException ();
#endif
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:10,代码来源:X509CertificateInitiatorClientCredential.cs


示例16: GetCertificateFromStore

        /// <summary>
        ///     Retrieves a certificate from the certificate store.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="name">The name.</param>
        /// <param name="findType">Type of the find.</param>
        /// <param name="value">The value.</param>
        /// <returns>A X509Certificate2</returns>
        public static X509Certificate2 GetCertificateFromStore(StoreLocation location, StoreName name,
            X509FindType findType, object value)
        {
            var store = new X509Store(name, location);

            try
            {
                store.Open(OpenFlags.ReadOnly);

                // work around possible bug in framework
                if (findType == X509FindType.FindByThumbprint)
                {
                    var thumbprint = value.ToString();
                    thumbprint = thumbprint.Trim();
                    thumbprint = thumbprint.Replace(" ", "");

                    foreach (var cert in store.Certificates)
                    {
                        if (string.Equals(cert.Thumbprint, thumbprint, StringComparison.OrdinalIgnoreCase) ||
                            string.Equals(cert.Thumbprint, thumbprint, StringComparison.InvariantCultureIgnoreCase))
                        {
                            return cert;
                        }
                    }
                }
                if (findType == X509FindType.FindBySerialNumber)
                {
                    var serial = value.ToString();
                    serial = serial.Trim();
                    serial = serial.Replace(" ", "");

                    foreach (var cert in store.Certificates)
                    {
                        if (string.Equals(cert.SerialNumber, serial, StringComparison.OrdinalIgnoreCase) ||
                            string.Equals(cert.SerialNumber, serial, StringComparison.InvariantCultureIgnoreCase))
                        {
                            return cert;
                        }
                    }
                }

                var certs = store.Certificates.Find(findType, value, false);

                if (certs.Count != 1)
                {
                    throw new InvalidOperationException(string.Format("Certificate not found: {0}", value));
                }

                return certs[0];
            }
            finally
            {
                store.Close();
            }
        }
开发者ID:azhuang88,项目名称:IdentityServer,代码行数:63,代码来源:X509Certificates.cs


示例17: FromStore

        /// <summary>
        /// Will deploy certificate found by find type and find value from the local certificate store, to remote certificate store on server with provided options.
        /// </summary>
        /// <param name="findType"></param>
        /// <param name="findValue"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IOfferRemoteDeployment FromStore(this IOfferRemoteCertDeployment remoteCert, X509FindType findType, string findValue, Action<IOfferCertificateOptions> options)
        {
            var certOptions = new CertificateOptions();
            if (options != null)
            {
                options(certOptions);
            }

            var remoteCertBuilder = ((RemoteCertDeploymentBuilder) remoteCert).RemoteDeployment;
            var certOp = new CertificateFromStoreOperation(findType, findValue, certOptions);
            Configure.Operation(remoteCertBuilder, certOp);
            return remoteCertBuilder;
        }
开发者ID:peteraglen,项目名称:condep-dsl-operations,代码行数:20,代码来源:RemoteCertDeploymentExtensions.cs


示例18: FromStore

        public IOfferRemoteDeployment FromStore(X509FindType findType, string findValue, Action<IOfferCertificateOptions> options)
        {
            var certOptions = new CertificateOptions();
            if (options != null)
            {
                options(certOptions);
            }

            var certOp = new CertificateFromStoreOperation(findType, findValue, certOptions);
            var compositeSequence = _remoteSequence.NewCompositeSequence(certOp);
            certOp.Configure(new RemoteCompositeBuilder(compositeSequence, _webDeploy));
            return _remoteDeploymentBuilder;
        }
开发者ID:brigs,项目名称:ConDep,代码行数:13,代码来源:RemoteCertDeploymentBuilder.cs


示例19: X509SecurityTokenProvider

		public X509SecurityTokenProvider (StoreLocation storeLocation,
			StoreName storeName, X509FindType findType, object findValue)
		{
			if (findValue == null)
				throw new ArgumentNullException ("findValue");

			store = new X509Store (storeName, storeLocation);
			store.Open (OpenFlags.ReadOnly);
			foreach (X509Certificate2 hit in store.Certificates.Find (findType, findValue, true)) {
				if (cert != null)
					throw new SecurityTokenException ("X509SecurityTokenProvider does not allow such certificate specification that indicates more than one certificate. Use more specific find value.");
				cert = hit;
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:X509SecurityTokenProvider.cs


示例20: SetScopedCertificate

 public void SetScopedCertificate(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findValue, Uri targetService)
 {
     if (findValue == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("findValue");
     }
     if (targetService == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("targetService");
     }
     this.ThrowIfImmutable();
     X509Certificate2 certificate = System.ServiceModel.Security.SecurityUtils.GetCertificateFromStore(storeName, storeLocation, findType, findValue, null);
     this.ScopedCertificates[targetService] = certificate;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:X509CertificateRecipientClientCredential.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# X509KeyStorageFlags类代码示例发布时间:2022-05-24
下一篇:
C# X509ContentType类代码示例发布时间: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