关于X509证书
代码如下:在我的机器上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();
}
}
}
但是在客户的机器上 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();
}
}
}
...全文
相关推荐
x509证书,x509证书,x509证书
x509 x509证书 x509证书 x509证书x509证书
通过OpenSSL解码X509证书文件
通过OpenSSL解码X509证书文件,包括*.cer/*.p7b/*.pfx格式文件。
C语言实现X509证书解析
1.C语言实现完整的X509证书解析方案; 2.解析出证书的序列号、公钥;
X509证书的各种操作
非对称加密的X509证书的加、解密操作,模拟创建证书、导入、导出。文件中包含两张含私钥证书。 (源程序转自互联网)
java生成X509证书jar包
基于BC已封装完成,导入项目直接调用RcertUtil工具类的方法即可使用制作x509证书,可导出到文件也可以返回证书对象


