2011-03-10 82 views
3

嗨Iam在我的C#項目中使用OpenSSL .NET包裝。我想生成一個X509認證,但我並不真正瞭解這個程序。又該它包含(什麼參數)...等 這是我的代碼,我這樣做是找一些測試後:OpenSSL .NET c#wrapper 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私鑰和摘要作爲參數和我必須配置它(日期...和其他參數)。 任何人都可以幫助我嗎?完成我的代碼?謝謝。

回答

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