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


C# X509Certificate.GetType方法代码示例

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


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

示例1: MakeEx

        //
        // Returns:
        //   For the input type == X509Certificate2 cert the same ref
        //   For an older cert format clones it as X509Certificate2 and returns result
        //   For a derived type clones it as X509Certificate2 and returns result
        //
        static X509Certificate2 MakeEx(X509Certificate certificate)
        {
            if (certificate.GetType() == typeof(X509Certificate2))
                return (X509Certificate2)certificate;

            X509Certificate2 certificateEx = null;
            try {
                if (certificate.Handle!=IntPtr.Zero) {
                    certificateEx = new X509Certificate2(certificate);
                }
            }
            catch (SecurityException) {
            }
            catch (CryptographicException) {
            }
            return certificateEx;
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:23,代码来源:_SecureChannel.cs

示例2: MakeEx

        private static X509Certificate2 MakeEx(X509Certificate certificate)
        {
            Debug.Assert(certificate != null, "certificate != null");

            if (certificate.GetType() == typeof(X509Certificate2))
            {
                return (X509Certificate2)certificate;
            }

            X509Certificate2 certificateEx = null;
            try
            {
                if (certificate.Handle != IntPtr.Zero)
                {
                    certificateEx = new X509Certificate2(certificate.Handle);
                }
            }
            catch (SecurityException) { }
            catch (CryptographicException) { }

            return certificateEx;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:22,代码来源:SecureChannel.cs

示例3: EnsurePrivateKey

        //
        // SECURITY: we open a private key container on behalf of the caller
        // and we require the caller to have permission associated with that operation.
        // After discussing with X509Certificate2 owners decided to demand KeyContainerPermission (Open)
        // At the same time we assert StorePermission on the caller frame since for consistency
        // we cannot predict when it will be demanded (SSL session reuse feature)
        //
        X509Certificate2 EnsurePrivateKey(X509Certificate certificate)
        {
            if (certificate == null)
                return null;

            if (Logging.On) Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_locating_private_key_for_certificate, certificate.ToString(true)));
            
            try {
                X509Certificate2 certEx = certificate as X509Certificate2;
                Type t = certificate.GetType();
                string certHash = null;

                // Protecting from X509Certificate2 derived classes
                if (t != typeof(X509Certificate2) && t != typeof(X509Certificate))
                {
                    if (certificate.Handle != IntPtr.Zero)
                    {
                        certEx = new X509Certificate2(certificate);
                        certHash = certEx.GetCertHashString();
                    }
                }
                else
                {
                    certHash = certificate.GetCertHashString();
                }

                if (certEx != null)
                {
                    if (certEx.HasPrivateKey)
                    {
                        if (Logging.On) Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_cert_is_of_type_2));
                        return certEx;
                    }

                    if ((object)certificate != (object) certEx)
                        certEx.Reset();
                }

                //
                // The certificate doesn't have a private key, so we need
                // to open the store and search for it there. Demand the
                // KeyContainerPermission with Open access before opening
                // the store. If store.Open() or store.Cert.Find()
                // demand the same permissions, then we should remove our
                // demand here.
                //
                #if FEATURE_MONO_CAS
                ExceptionHelper.KeyContainerPermissionOpen.Demand(); 
                #endif
                
                X509Certificate2Collection collectionEx;

                // ELSE Try MY user and machine stores for private key check
                // For server side mode MY machine store takes priority
                X509Store store = EnsureStoreOpened(m_ServerMode);
                if (store != null)
                {
                    collectionEx = store.Certificates.Find(X509FindType.FindByThumbprint, certHash, false);
                    if (collectionEx.Count > 0 && collectionEx[0].HasPrivateKey)
                    {
                        if (Logging.On) Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_found_cert_in_store, (m_ServerMode ? "LocalMachine" : "CurrentUser")));
                        return collectionEx[0];
                    }
                }

                store = EnsureStoreOpened(!m_ServerMode);
                if (store != null)
                {
                    collectionEx = store.Certificates.Find(X509FindType.FindByThumbprint, certHash, false);
                    if (collectionEx.Count > 0 && collectionEx[0].HasPrivateKey)
                    {
                        if (Logging.On) Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_found_cert_in_store, (m_ServerMode ? "CurrentUser" : "LocalMachine")));
                        return collectionEx[0];
                    }
                }
            }
            catch (CryptographicException) {
            }

            if (Logging.On) Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_did_not_find_cert_in_store));

            return null;
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:90,代码来源:_SecureChannel.cs

示例4: EnsurePrivateKey

 private X509Certificate2 EnsurePrivateKey(X509Certificate certificate)
 {
     if (certificate != null)
     {
         if (Logging.On)
         {
             Logging.PrintInfo(Logging.Web, this, SR.GetString("net_log_locating_private_key_for_certificate", new object[] { certificate.ToString(true) }));
         }
         try
         {
             X509Certificate2Collection certificates;
             X509Certificate2 certificate2 = certificate as X509Certificate2;
             Type type = certificate.GetType();
             string findValue = null;
             if ((type != typeof(X509Certificate2)) && (type != typeof(X509Certificate)))
             {
                 if (certificate.Handle != IntPtr.Zero)
                 {
                     certificate2 = new X509Certificate2(certificate);
                     findValue = certificate2.GetCertHashString();
                 }
             }
             else
             {
                 findValue = certificate.GetCertHashString();
             }
             if (certificate2 != null)
             {
                 if (certificate2.HasPrivateKey)
                 {
                     if (Logging.On)
                     {
                         Logging.PrintInfo(Logging.Web, this, SR.GetString("net_log_cert_is_of_type_2"));
                     }
                     return certificate2;
                 }
                 if (certificate != certificate2)
                 {
                     certificate2.Reset();
                 }
             }
             ExceptionHelper.KeyContainerPermissionOpen.Demand();
             X509Store store = EnsureStoreOpened(this.m_ServerMode);
             if (store != null)
             {
                 certificates = store.Certificates.Find(X509FindType.FindByThumbprint, findValue, false);
                 if ((certificates.Count > 0) && (certificates[0].PrivateKey != null))
                 {
                     if (Logging.On)
                     {
                         Logging.PrintInfo(Logging.Web, this, SR.GetString("net_log_found_cert_in_store", new object[] { this.m_ServerMode ? "LocalMachine" : "CurrentUser" }));
                     }
                     return certificates[0];
                 }
             }
             store = EnsureStoreOpened(!this.m_ServerMode);
             if (store != null)
             {
                 certificates = store.Certificates.Find(X509FindType.FindByThumbprint, findValue, false);
                 if ((certificates.Count > 0) && (certificates[0].PrivateKey != null))
                 {
                     if (Logging.On)
                     {
                         Logging.PrintInfo(Logging.Web, this, SR.GetString("net_log_found_cert_in_store", new object[] { this.m_ServerMode ? "CurrentUser" : "LocalMachine" }));
                     }
                     return certificates[0];
                 }
             }
         }
         catch (CryptographicException)
         {
         }
         if (Logging.On)
         {
             Logging.PrintInfo(Logging.Web, this, SR.GetString("net_log_did_not_find_cert_in_store"));
         }
     }
     return null;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:79,代码来源:SecureChannel.cs


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