C# X509Store.Certificates.Find(FindBySerialNumber)不匹配

C# X509Store.Certificates.Find(FindBySerialNumber)不匹配,c#,x509certificate,C#,X509certificate,在我开始之前,这不是这个QA()的副本-我使用的指纹字符串是40个字符长,不包含任何从MMC复制的隐藏字符 以下是我使用的代码: String thumbprint = "c112345678904655585e8c8244af5d3f2630498b".ToUpperInvariant(); assert( thumbprint.Length == 40 ); X509Store store = new X509Store(StoreName.My, StoreLocation.Curren

在我开始之前,这不是这个QA()的副本-我使用的指纹字符串是40个字符长,不包含任何从MMC复制的隐藏字符

以下是我使用的代码:

String thumbprint = "c112345678904655585e8c8244af5d3f2630498b".ToUpperInvariant();
assert( thumbprint.Length == 40 );

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);

X509Certificate2Collection matches = store.Certificates.Find(X509.FindType.FindBySerialNumber, thumbprint, validOnly: false );
assert( matches.Count == 1 ); // this fails, the count is == 0.
但当我手动查询证书时,没关系:

assert( store.Certificates.Count == 1 ); // there is only 1 cert in the store
X509Certificate2 cert = store.Certificates[0];

assert( cert.Thumbprint == thumbprint ); // this passes
这是什么原因造成的?当存在完全匹配的证书时,
Find
为什么不返回证书


这篇MSDN博客文章描述了同样的情况,但没有提供任何解释:

我使用的是
X509.FindType.FindBySerialNumber
,而不是
X509.FindType.FindByThumbprint
。它现在正在工作。

我使用的是
X509.FindType.FindBySerialNumber
而不是
X509.FindType.FindByThumbprint
,但我没有意识到这一点。它正在工作。

.Find(X509.FindType.FindBySerialNumber,指纹,有效:false)@罗布·德普!谢谢查找(X509.FindType.FindBySerialNumber,指纹,有效:false)@罗布·德普!谢谢