小编nun*_*mel的帖子

X509Store Certificates.Find FindByThumbprint的问题

我使用这个方法时遇到了问题 X509Store.Certificates.Find

public static X509Certificate2 FromStore(StoreName storeName, 
          StoreLocation storeLocation, X509FindType findType, string findValue)
{
    X509Store store = new X509Store(storeName, storeLocation);
    store.Open(OpenFlags.ReadOnly);
    try
    {
        //findValue = "7a6fa503ab57b81d6318a51ca265e739a51ce660"
        var results = store.Certificates.Find(findType, findValue, true);

        return results[0];                
    }
    finally
    {
        store.Close();
    }
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,Find方法返回0 results(results.Count == 0),但如果我将findValue作为常量,则该方法会找到证书.

public static X509Certificate2 FromStore(StoreName storeName, 
           StoreLocation storeLocation, X509FindType findType, string findValue)
{
    X509Store store = new X509Store(storeName, storeLocation);
    store.Open(OpenFlags.ReadOnly);
    try
    {         
        //findValue= "7a6fa503ab57b81d6318a51ca265e739a51ce660"
        var results = store.Certificates.Find(findType, 
                              "7a6fa503ab57b81d6318a51ca265e739a51ce660", true);
        return results[0];
    }
    finally
    { …
Run Code Online (Sandbox Code Playgroud)

c# wcf certificate ssl-certificate x509certificate

81
推荐指数
6
解决办法
5万
查看次数

标签 统计

c# ×1

certificate ×1

ssl-certificate ×1

wcf ×1

x509certificate ×1