Problems with X509Store Certificates.Find FindByThumbprint

后端 未结 14 2154
醉话见心
醉话见心 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:16

    This tripped me up too, I wrote this function to clean the thumbprint when copied and pasted from MMC:

    public string CleanThumbprint(string mmcThumbprint)
        {
            //replace spaces, non word chars and convert to uppercase
            return Regex.Replace(mmcThumbprint, @"\s|\W", "").ToUpper();
        }
    
    ...
            var myThumbprint = CleanThumbprint("‎b3 ab 84 e5 1e e5 e4 75 e7 a5 3e 27 8c 87 9d 2f 05 02 27 56");
            var myCertificate = certificates.Find(X509FindType.FindByThumbprint, myThumbprint, true)[0];
    

提交回复
热议问题