OpenSSL .NET c#wrapper X509认证

时间:2011-03-10 20:03:48

标签: c# .net openssl x509

我喜欢在我的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 个答案:

答案 0 :(得分: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);