OpenSSL的.NET C#包装X509认证 [英] OpenSSL .NET c# wrapper X509 certification

查看:160
本文介绍了OpenSSL的.NET C#包装X509认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

荫使用OpenSSL的.NET包装在我的C#项目嗨。我想生成X509证书,但我真的不知道该过程。又该它包含(什么参数)...等 这是我的code,我找了一些测试后,做到了:

Hi Iam using the OpenSSL .NET wrapper in my c# project. i want to generate an X509 certification but i don't really know the procedure. what should it contain (what parameters)...etc this is my code, I did it after looking some tests:

        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私钥和摘要作为参数,我必须配置(日期...等参数)。 任何一个可以帮助我这个问题?完成我的code?谢谢你。

I suppose that the certificate should take RSA private key and the digest as parameters and i have to configure it (date...and others parameters). Can any one help me about that ? to finish my code ? thank you.

推荐答案

我用下面的程序:

// 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);

这篇关于OpenSSL的.NET C#包装X509认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆