我需要获取计算机中的发出证书的主体的名称以及发出证书的主体的名称.
微软提供的getname()方法和GetIssuerName()方法现在都已经过时了,有没有谁知道和这个差不多的方法?或者类似方法?
微软提供的getname()方法和GetIssuerName()方法现在都已经过时了,有没有谁知道和这个差不多的方法?或者类似方法?
解决方案 »
- 新手求指教
- TextChanged 事件响应交互更改
- VS2008+SQL2005开发的程序,如果数据库转移到SQL2000上会不会出问题
- 如何实现把word文件转换成.mht格式的???
- .net全角半角自动切换,急急。。。。。。。
- 打开的与此连接相关联的 DataReader,只有40分了,都给了
- 在一个程序中创建了一个Thread0(socket receive message)循环线程,如果在这个线程中可能会有几个同步的消息,为何响应了一个Fun1时(此消息
- 这样写哪里不行呢
- 有高人帮下忙吗? 使用ASP.net 为ASP(.asp,不是.aspx)页面进行URL重写(UrlRewrite)
- WPF如何实现不锁定主界面的弹窗功能?
- 静态方法和非静太方法有什么区别?
- 关于C#强制转换的问题
using System.Security.Cryptography;
using System.Security.Permissions;
using System.IO;
using System.Security.Cryptography.X509Certificates;
public class CertInfo
{
//Reads a file.
internal static byte[] ReadFile (string fileName)
{
FileStream f = new FileStream(fileName, FileMode.Open, FileAccess.Read);
int size = (int)f.Length;
byte[] data = new byte[size];
size = f.Read(data, 0, size);
f.Close();
return data;
}
//Main method begins here.
public static void Main(string[] args)
{
//Test for correct number of arguments.
if (args.Length < 1)
{
Console.WriteLine("Usage: CertInfo <filename>");
return;
}
try
{
X509Certificate2 x509 = new X509Certificate2();
//Create X509Certificate2 object from .cer file.
byte[] rawData = ReadFile(args[0]);
x509.Import(rawData); //Print to console information contained in the certificate.
Console.WriteLine("{0}Subject: {1}{0}", Environment.NewLine,x509.Subject);
Console.WriteLine("{0}Issuer: {1}{0}", Environment.NewLine,x509.Issuer);
Console.WriteLine("{0}Version: {1}{0}", Environment.NewLine,x509.Version);
Console.WriteLine("{0}Valid Date: {1}{0}", Environment.NewLine,x509.NotBefore);
Console.WriteLine("{0}Expiry Date: {1}{0}", Environment.NewLine,x509.NotAfter);
Console.WriteLine("{0}Thumbprint: {1}{0}", Environment.NewLine,x509.Thumbprint);
Console.WriteLine("{0}Serial Number: {1}{0}", Environment.NewLine,x509.SerialNumber);
Console.WriteLine("{0}Friendly Name: {1}{0}", Environment.NewLine,x509.PublicKey.Oid.FriendlyName);
Console.WriteLine("{0}Public Key Format: {1}{0}", Environment.NewLine,x509.PublicKey.EncodedKeyValue.Format(true));
Console.WriteLine("{0}Raw Data Length: {1}{0}", Environment.NewLine,x509.RawData.Length);
Console.WriteLine("{0}Certificate to string: {1}{0}", Environment.NewLine,x509.ToString(true)); Console.WriteLine("{0}Certificate to XML String: {1}{0}", Environment.NewLine,x509.PublicKey.Key.ToXmlString(false)); //Add the certificate to a X509Store.
X509Store store = new X509Store();
store.Open(OpenFlags.MaxAllowed);
store.Add(x509);
store.Close();
} catch (DirectoryNotFoundException)
{
Console.WriteLine("Error: The directory specified could not be found.");
}
catch (IOException)
{
Console.WriteLine("Error: A file in the directory could not be accessed.");
}
catch (NullReferenceException)
{
Console.WriteLine("File must be a .cer file. Program does not have access to that type of file.");
}
}}