关于X509证书

kkk3k3k kkk3k3k 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:在我的机器上WIn7 32位旗舰版 一起运行正常 可以获取证书信息,在XP的机器上也运行正确

但是在客户的机器上 WIn7 64位旗舰版, StoreName.My和AddressBook都没有得到证书信息,也没有发生异常

现在想知道原因? 是缺少权限还是其他什么原因? 非常感谢 不吝赐教。
------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.IO;

namespace ConsoleApplication1
{
class Program
{

static void Log(string logMessage)
{
using (StreamWriter w = File.AppendText("运行结果.txt"))
{

w.WriteLine(" -- :{0}", logMessage);

}
}

static void ShowMsg(X509Certificate2 cer)
{

Log(string.Format("-----------------------------------------------------------"));
Log(string.Format("主题: {0}", cer.Subject));
Log(string.Format("颁发者: {0}", cer.Issuer));
Log(string.Format("版本: {0}", cer.Version));
Log(string.Format("有效日期: {0}", cer.NotBefore));
Log(string.Format("过期日期: {0}", cer.NotAfter));
Log(string.Format("指纹: {0}", cer.Thumbprint));
Log(string.Format("序列号: {0}", cer.SerialNumber));
Log(string.Format("友好名: {0}", cer.PublicKey.Oid.FriendlyName));
Log(string.Format("公钥格式: {0}", cer.PublicKey.EncodedKeyValue.Format(true)));
Log(string.Format("原始数据长度: {0}", cer.RawData.Length));


}

static void Main(string[] args)
{

Log("#################################################################################");
Log("#################################################################################");

try
{


X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.MaxAllowed);
X509Certificate2Collection storecollection = (X509Certificate2Collection)store.Certificates;
Log("证书个数:"+storecollection.Count.ToString());
foreach (X509Certificate2 x509 in storecollection) ShowMsg(x509);



}
catch(Exception e)
{
Log(e.Message);
}

Log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
Log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");


try
{

X509Store store = new X509Store(StoreName.AddressBook, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection storecollection = (X509Certificate2Collection)store.Certificates;
Log("证书个数:" + storecollection.Count.ToString());
foreach (X509Certificate2 x509 in storecollection) ShowMsg(x509);

}
catch(Exception e)
{
Log(e.Message);
}


System.Console.WriteLine("已经运行完成,按任意键退出,结果请看[运行结果.txt]");
System.Console.ReadLine();

}


}
}
...全文
评论 7
收藏 已收藏
分享
返回顶部
kkk3k3k
C# 111,130 成员 642,541 内容