当前位置: 首页>>代码示例>>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;未经允许,请勿转载。