无法获得X509Certificate2证书的代码C#

编程入门 行业动态 更新时间:2024-10-19 00:20:51
本文介绍了无法获得X509Certificate2证书的代码C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从我的商店找到证书,但使用以下代码我无法获得证书。它总是返回null。

我的代码有什么问题?

更新: >

我通过探索store对象复制了我的证书指纹,并将其与我的指纹字符串进行比较,并返回false!我认为在VS2010 IDE或复制粘贴问题解释字符串的问题,你可以看到下面的图。因为它应该忽略来自列表的证书。有没有人面临这种​​类型的问题?

解决方案

证书集合是空的,因为没有指纹的证书。 检查:

  • 证书在您当前用户中的存在

    • 使用mmc验证上述内容

    • $ c> X509Store store = new X509Store(StoreName.Root,StoreLocation.CurrentUser);

    修改:

    以下是否有用:

    X509Certificate2Collection col = store.Certificates; foreach(var currCert in col) { var currThumbprint = currCert.Thumbprint; if(thumbprint.ToUpperInvariant()== currThumbprint) { x509Certificate2 = currCert; break; } }

    I want to find certificate from my store but using following code i could not able to get certificate. It always return null.

    What's wrong with my code?

    Update:

    I have copied my certificate thumbprint by exploring store object and compare it with my thumbprint string and it return false! I think issue of interpreting string in VS2010 IDE or copy paste problem you can see that below in fig. because of this it should ignore the certificate from the list. Have anyone faced this type of issue before?

    解决方案

    Well the certificate collection is empty since there's no certificate with that thumbprint. Check:

    • that the certificate is present in your current user

    • that the certificate is stored in the personal folder

    Try:

    • using mmc to verify the above things

    • using X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);

    Edit:

    Does the following return anything useful:

    X509Certificate2Collection col = store.Certificates; foreach (var currCert in col) { var currThumbprint = currCert.Thumbprint; if (thumbprint.ToUpperInvariant() == currThumbprint) { x509Certificate2= currCert; break; } }

更多推荐

无法获得X509Certificate2证书的代码C#

本文发布于:2023-11-13 02:09:14,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:证书   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!