當前位置: 首頁>>代碼示例>>C#>>正文


C# X509Store.?.Close方法代碼示例

本文整理匯總了C#中System.Security.Cryptography.X509Certificates.X509Store.?.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# X509Store.?.Close方法的具體用法?C# X509Store.?.Close怎麽用?C# X509Store.?.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Security.Cryptography.X509Certificates.X509Store的用法示例。


在下文中一共展示了X509Store.?.Close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetCertificate

        /// <summary>
        /// Retrieves an X509 Certificate from the specified store and location
        /// </summary>
        /// <param name="thumbprint">The certificate thumbprint</param>
        /// <param name="storeName">The name of the store to retrieve the information from</param>
        /// <param name="storeLocation">The location within the store where the certificate is located</param>
        /// <returns>An X509 certificate with the specified thumbprint if available or null if not</returns>
        public static X509Certificate2 GetCertificate(string thumbprint, StoreName storeName, StoreLocation storeLocation)
        {
            X509Store store = null;
            X509Certificate2 certificate;

            try
            {
                store = new X509Store(storeName, storeLocation);
                store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection collection = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);

                certificate = collection.Count == 0 ? null : collection[0];
            }
            finally
            {
                store?.Close();
            }

            return certificate;
        }
開發者ID:nayato,項目名稱:azure-iot-protocol-gateway,代碼行數:27,代碼來源:CertificateUtilities.cs

示例2: GetCertificate

        public static X509Certificate2 GetCertificate(StoreLocation location, string subjectName)
        {
            X509Certificate2 cert = null;
            var store = new X509Store(StoreName.My, location);
            store.Open(OpenFlags.ReadOnly);
            try
            {
                X509Certificate2Collection certs = store.Certificates.Find(
                                                       X509FindType.FindBySubjectName,
                                                       subjectName,
                                                       false);
                if (certs.Count == 1)
                {
                    cert = certs[0];
                }
                else
                {
                    cert = null;
                }
            }
            finally
            {
                store?.Close();
            }

            return cert;
        }
開發者ID:devworker55,項目名稱:Mammatus,代碼行數:27,代碼來源:CertificateHelper.cs

示例3: FindCertificates

        /// <summary>
        /// Find certificates matching some predicate.
        /// </summary>
        /// <param name="predicate">The function used to determine which certificates to include.</param>
        /// <returns>The matching certificates.</returns>
        public static IEnumerable<X509Certificate2> FindCertificates(Func<X509Certificate2, bool> predicate)
        {
            var stores = Enum.GetValues(typeof(StoreName)).Cast<StoreName>().ToArray();
            var locations = Enum.GetValues(typeof(StoreLocation)).Cast<StoreLocation>().ToArray();

            var certificates = new List<X509Certificate2>();

            foreach (var store in stores)
            {
                foreach (var location in locations)
                {
                    X509Store source = null;
                    try
                    {
                        source = new X509Store(store, location);
                        source.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
                        certificates.AddRange(source.Certificates
                            .Cast<X509Certificate2>()
                            .Where(x => !x.Archived)
                            .Where(x => x.NotAfter >= DateTime.Now)
                            .Where(x => x.NotBefore <= DateTime.Now)
                            .Where(predicate)
                            .Where(x => x.Verify())
                            );
                    }
                    catch
                    {
                        // Just try the next one
                    }
                    finally
                    {
                        source?.Close();
                    }
                }
            }

            return certificates;
        }
開發者ID:bungeemonkee,項目名稱:Configgy,代碼行數:43,代碼來源:EncryptionUtility.cs


注:本文中的System.Security.Cryptography.X509Certificates.X509Store.?.Close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。