OpenSSL .NET c# 包装器 X509 证书

3

你好,我在我的c#项目中使用OpenSSL .NET包装器。我想生成一个X509证书,但我不知道具体的步骤。它应该包含什么(哪些参数)...等等。这是我的代码,我是在查看一些测试后编写的:

        OpenSSL.X509.X509Certificate x509 = new OpenSSL.X509.X509Certificate();
        OpenSSL.Crypto.RSA rsa = new OpenSSL.Crypto.RSA();
        rsa.GenerateKeys(1024, 0x10001, null, null);
        OpenSSL.Crypto.CryptoKey key = new OpenSSL.Crypto.CryptoKey(rsa);
        OpenSSL.Crypto.MessageDigestContext digest = new OpenSSL.Crypto.MessageDigestContext(
                                                                 OpenSSL.Crypto.MessageDigest.SHA1);

我认为证书应该以RSA私钥和摘要作为参数,我需要配置它(日期和其他参数)。有人能帮我完成这个代码吗?谢谢。

1个回答

2
我使用以下例程:
// Initialize the following with your information
var serial = 1234;
var issuer = new X509Name("issuer");
var subject = new X509Name("subject");

// Creates the key pair
var rsa = new RSA();
rsa.GenerateKeys(1024, 0x10001, null, null);

// Creates the certificate
var key = new CryptoKey(rsa);
var cert = new X509Certificate(serial, subject, issuer, key, DateTime.Now, DateTime.Now.AddYears(20));

// Dumps the certificate into a .cer file
var bio = BIO.File("C:/temp/cert.cer", "w");
cert.Write(bio);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接