Problems with X509Store Certificates.Find FindByThumbprint

后端 未结 14 2082
醉话见心
醉话见心 2020-12-04 20:56

I\'m having a problem when I use the method X509Store.Certificates.Find

public static X509Certificate2 FromStore(StoreName storeName, 
                  


        
14条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 21:29

    Here is the simple version of code for the above suggestions- ofcourse which is worked for me

     private X509Certificate2 GetCertificate()
        {
            var certStore = new X509Store("my");
            certStore.Open(OpenFlags.ReadOnly);
            try
            {
                const string thumbprint = "18 33 fe 3a 67 d1 9e 0d f6 1e e5 d5 58 aa 8a 97 8c c4 d8 c3";
                var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint,
                Regex.Replace(thumbprint, @"\s+", "").ToUpper(), false);
                if (certCollection.Count > 0)
                    return certCollection[0];
            }
            finally
            {
                certStore.Close();
            }
            return null;
        }
    

提交回复
热议问题