OpenSSL .NET c# wrapper X509 certification

前端 未结 1 1361
半阙折子戏
半阙折子戏 2021-01-21 03:35

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)

相关标签:
1条回答
  • 2021-01-21 04:03

    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);
    
    0 讨论(0)
提交回复
热议问题