Problems with X509Store Certificates.Find FindByThumbprint

后端 未结 14 1949
醉话见心
醉话见心 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;
        }
    
    0 讨论(0)
  • 2020-12-04 21:30

    This code should work.

    I suppose you have copied this thumbprint from the certificate management console. And that copied value contains unicode non-readable symbol which is invisible in Visual Studio. Try to delete the first invisible symbol and if this is what I think of, this should work.

    0 讨论(0)
提交回复
热议问题