简体   繁体   English

OpenSSL .NET C#包装器X509认证

[英]OpenSSL .NET c# wrapper X509 certification

Hi Iam using the OpenSSL .NET wrapper in my c# project. 嗨,我在c#项目中使用OpenSSL .NET包装器。 i want to generate an X509 certification but i don't really know the procedure. 我想生成X509认证,但我真的不知道程序。 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);

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). 我想该证书应将RSA私钥和摘要作为参数,并且我必须对其进行配置(日期...和其他参数)。 Can any one help me about that ? 有人可以帮我吗? to finish my code ? 完成我的代码? thank you. 谢谢。

I use the following routine: 我使用以下例程:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM