在C#中使用 makecert 创建自签名的证书
2007-07-04 09:23
169 查看
class Program
{
static void Main(string[] args)
{
X509Certificate2 cert = CreateCertificate();
//cert.ToString();
Console.Write(cert.ToString());
Console.Read();
}
public static X509Certificate2 CreateCertificate()
{
// makecert -r -pe -n "CN=TestUser" -ss my -sr currentuser
// -sky exchange ./TestUser.cer
//const string MakeCert = "C://Program Files//Microsoft Visual Studio 8//Common7//Tools//Bin//makecert.exe";
const string MakeCert = "C://Program Files//Microsoft Visual Studio 8//SDK//v2.0//Bin//makecert.exe";
//string fileName = Path.ChangeExtension(Path.GetTempFileName(), "cer");
string fileName = Path.ChangeExtension("d://", "cer");
string userName = Guid.NewGuid().ToString();
string arguments =
string.Format("-r -pe -n /"CN=
{0}/" -ss my -sr currentuser -sky exchange /"
{1}/"",
userName, fileName);
Process p = Process.Start(MakeCert, arguments);
p.WaitForExit();
byte[] certBytes = ReadFile(fileName);
X509Certificate2 cert = new X509Certificate2(certBytes);
return cert;
}
internal static byte[] ReadFile(string fileName)
{
using (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);
return data;
}
}
}
相关文章推荐
- 在C#中使用 makecert 创建自签名的证书
- 在C#中使用 makecert 创建自签名的证书
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- (转)C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- 使用Let's Encrypt证书签名服务创建Java Keystore(.jks)
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密(转)
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- 创建和使用自签名证书
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- Golang1.7.3使用x509标准库创建自签名证书和签发名其他证书
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- 使用openssl创建自签名证书及部署到IIS教程
- C#创建https请求并使用pfx证书
- (转)C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- 创建 Android 上使用的自签名证书(Creating self-signed certificates for use on Android)
- 证书创建工具Makecert工具使用参数说明