热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何检索X509Store中的所有证书-HowtoretrieveallcertificatesinyourX509Store

IamusingthefollowingcodetoretrieveallcertificatesinmyPCfromanasp.netwebapp.Thecert

I am using the following code to retrieve all certificates in my PC from an asp.net webapp. The certificates collection is empty, and I can't understand why.

我正在使用以下代码从asp.net webapp中检索PC中的所有证书。证书集合是空的,我不明白为什么。

I tried impersonating my own user account and I didn't succeed as well. What am I doing wrong?

我尝试模仿我自己的用户帐户,但也没有成功。我做错了什么?

var store = new X509Store(StoreLocation.CurrentUser); //StoreLocation.LocalMachine fails too
var certificates = store.Certificates;
foreach (var certificate in certificates)
{
    var friendlyName = certificate.FriendlyName;
    Console.WriteLine(friendlyName);
}

//original problem: fetch a single certificate by its subject name
X509Certificate2 clientCertificate = CertificateUtility.GetCertificate(StoreName.My, StoreLocation.CurrentUser,  "CN=mypc.domainname"); //returns null :(

4 个解决方案

#1


47  

Add this line of code to the second line and see how it works:

将这一行代码添加到第二行,看看它是如何工作的:

store.Open(OpenFlags.ReadOnly);

and then this at the bottom :):

下面是这个:

store.Close();

#2


16  

All in one ...

所有在一个…

I have an apache server (xamp) with https. I access through https and c# (vs2010) to a PHP upload page

我有一个带有https的apache服务器(xamp)。我通过https和c# (vs2010)访问PHP上传页面

  1. Install the certificate from i.e in the personal folder certificate, for example.

    安装来自i的证书。e在个人文件夹证书中,例如。

  2. To view the certicates run "certmgr.msc" , at least in win7

    要查看运行的certmgr。至少在win7中是这样

Listing the personal certificates

var store = new X509Store(StoreLocation.CurrentUser); 

store.Open(OpenFlags.ReadOnly); 

var certificates = store.Certificates;
foreach (var certificate in certificates)
{
    var friendlyName = certificate.FriendlyName;
    var xname = certificate.GetName(); //obsolete
    Console.WriteLine(friendlyName);
}

store.Close();

Find specific certificate

string certificateName = "CN=localhost"; //name found in the var xname
X509Store storex = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                    storex.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificatesx =
            storex.Certificates.Find(X509FindType.FindBySubjectName, 
            certificateName,
            true);

X509Certificate certificatex = certificates[0];

storex.Close();

#3


2  

I can find certificates by ...

我可以通过…

var certificateStore = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine);

certificateStore.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

var certificateCollection = certificateStore.Certificates.Find(X509FindType.FindBySubjectName, "mycert.me.com",false);

certificateStore.Close();

var certificate = certificateCollection[0];

certificateCollection will have the certificates I care about ... if it is just one then I get first element in the collection.

证书汇总会有我关心的证书……如果它是1,那么我得到集合中的第一个元素。

#4


1  

Look in your certificate store(mmc/add/certificate snap-in/my user account/Certificates - Current User/Personal/Certificates) to see the subject name to make sure "CN=mypc.domainname" is whats actually on the cert.

查看您的证书存储(mmc/add/certificate snapin /my user account/Certificates - Current user /Personal/Certificates),查看主题名称,以确保“CN=mypc”。domainname是在cert上的。

"CN=mypc.domainname"

vs

vs

"CN = mypc.domainname"

...etc


推荐阅读
  • 一、路由首先需要配置路由,就是点击good组件进入goodDetail组件配置路由如下{path:goodDetail,component:goodDetail}同时在good组件中写入如下点击事件,路由中加入 ... [详细]
  • Google Play推出全新的应用内评价API,帮助开发者获取更多优质用户反馈。用户每天在Google Play上发表数百万条评论,这有助于开发者了解用户喜好和改进需求。开发者可以选择在适当的时间请求用户撰写评论,以获得全面而有用的反馈。全新应用内评价功能让用户无需返回应用详情页面即可发表评论,提升用户体验。 ... [详细]
  • phpcomposer 那个中文镜像是不是凉了 ... [详细]
  • 树莓派语音控制的配置方法和步骤
    本文介绍了在树莓派上实现语音控制的配置方法和步骤。首先感谢博主Eoman的帮助,文章参考了他的内容。树莓派的配置需要通过sudo raspi-config进行,然后使用Eoman的控制方法,即安装wiringPi库并编写控制引脚的脚本。具体的安装步骤和脚本编写方法在文章中详细介绍。 ... [详细]
  • Python实现变声器功能(萝莉音御姐音)的方法及步骤
    本文介绍了使用Python实现变声器功能(萝莉音御姐音)的方法及步骤。首先登录百度AL开发平台,选择语音合成,创建应用并填写应用信息,获取Appid、API Key和Secret Key。然后安装pythonsdk,可以通过pip install baidu-aip或python setup.py install进行安装。最后,书写代码实现变声器功能,使用AipSpeech库进行语音合成,可以设置音量等参数。 ... [详细]
  • 本文讲述了如何通过代码在Android中更改Recycler视图项的背景颜色。通过在onBindViewHolder方法中设置条件判断,可以实现根据条件改变背景颜色的效果。同时,还介绍了如何修改底部边框颜色以及提供了RecyclerView Fragment layout.xml和项目布局文件的示例代码。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文介绍了游标的使用方法,并以一个水果供应商数据库为例进行了说明。首先创建了一个名为fruits的表,包含了水果的id、供应商id、名称和价格等字段。然后使用游标查询了水果的名称和价格,并将结果输出。最后对游标进行了关闭操作。通过本文可以了解到游标在数据库操作中的应用。 ... [详细]
  • 如何在php中将mysql查询结果赋值给变量
    本文介绍了在php中将mysql查询结果赋值给变量的方法,包括从mysql表中查询count(学号)并赋值给一个变量,以及如何将sql中查询单条结果赋值给php页面的一个变量。同时还讨论了php调用mysql查询结果到变量的方法,并提供了示例代码。 ... [详细]
  • 本文详细介绍了git常用命令及其操作方法,包括查看、添加、提交、删除、找回等操作,以及如何重置修改文件、抛弃工作区修改、将工作文件提交到本地暂存区、从版本库中删除文件等。同时还介绍了如何从暂存区恢复到工作文件、恢复最近一次提交过的状态,以及如何合并多个操作等。 ... [详细]
  • 本文介绍了如何使用PHP代码将表格导出为UTF8格式的Excel文件。首先,需要连接到数据库并获取表格的列名。然后,设置文件名和文件指针,并将内容写入文件。最后,设置响应头部,将文件作为附件下载。 ... [详细]
  • Python操作MySQL(pymysql模块)详解及示例代码
    本文介绍了使用Python操作MySQL数据库的方法,详细讲解了pymysql模块的安装和连接MySQL数据库的步骤,并提供了示例代码。内容涵盖了创建表、插入数据、查询数据等操作,帮助读者快速掌握Python操作MySQL的技巧。 ... [详细]
  • 本文是一篇翻译文章,介绍了async/await的用法和特点。async关键字被放置在函数前面,意味着该函数总是返回一个promise。文章还提到了可以显式返回一个promise的方法。该特性使得async/await更易于理解和使用。本文还提到了一些可能的错误,并希望读者能够指正。 ... [详细]
  • x86 linux的进程调度,x86体系结构下Linux2.6.26的进程调度和切换
    进程调度相关数据结构task_structtask_struct是进程在内核中对应的数据结构,它标识了进程的状态等各项信息。其中有一项thread_struct结构的 ... [详细]
  • Iwanttointegratesort,order,maxandoffsetinafindAllquery.Thefollowingworksfine:我想在fin ... [详细]
author-avatar
黑夜总好漫长Q
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有