How can I create x509 certificate using Bouncy Castle in c#
I'm trying to generate an x509 certificate using Bouncy Castle in c#

the certificate I want to create have following information 
  

Basic Constraints:

    Subject Type=End Entity
    Path Length Constraint=None

Authority Key Identifier:

    KeyID=ca a8 92 7f a2 1c 81 46 cb 4a fc e4 c4 83 7d c3 41 9e f4 14
    Certificate Issuer:
         Directory Address:
          CN=test01
          OU=SIT
          O=Internet Widgits Pty Ltd
          S=Some-State
          C=AU
    Certificate SerialNumber=00 e9 db 3d d9 9f e1 1d 1e
  

which generated using openssl


but when I use following code

    var kpgen = new RsaKeyPairGenerator();
            kpgen.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), 1024));
            var cerKp = kpgen.GenerateKeyPair();

            IDictionary attrs = new Hashtable();
            attrs[X509Name.E] = user_email;
            attrs[X509Name.Name] = user_name;
            attrs[X509Name.UID] = account_user;
            attrs[X509Name.OU] = user_orgUnit;
            attrs[X509Name.O] = user_org;
            attrs[X509Name.C] = "TH";

            IList ord = new ArrayList();
            ord.Add(X509Name.E);
            ord.Add(X509Name.Name);
            ord.Add(X509Name.UID);
            ord.Add(X509Name.OU);
            ord.Add(X509Name.O);
            ord.Add(X509Name.C);

            X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

            certGen.SetSerialNumber(BigInteger.One);

            certGen.SetIssuerDN(new X509Name(ord, attrs));
            certGen.SetNotBefore(DateTime.Today.Subtract(new TimeSpan(1, 0, 0, 0)));
            certGen.SetNotAfter(DateTime.Today.AddDays(365));
            certGen.SetSubjectDN(new X509Name(ord, attrs));
            certGen.SetPublicKey(cerKp.Public);
            certGen.SetSignatureAlgorithm("SHA1WithRSA");

            X509Certificate x509 = certGen.Generate(cerKp.Private);

            System.Security.Cryptography.X509Certificates.X509Certificate x509_ = DotNetUtilities.ToX509Certificate(x509);
            System.Security.Cryptography.X509Certificates.X509Certificate2 x509__ = new System.Security.Cryptography.X509Certificates.X509Certificate2(x509_);
            
            certificate_data = x509__.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Cert);
            byte[] pvk_data = x509__.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Pfx, "password");
            
            //write certificate file
            FileStream fs = new FileStream(certificatePath, FileMode.CreateNew);
            fs.Write(certificate_data, 0, certificate_data.Length);
            fs.Flush();
            fs.Close();

            setPrivateKeyPath();

            FileStream fs2 = new FileStream(privateKeyPath, FileMode.CreateNew);
            fs2.Write(pvk_data, 0, pvk_data.Length);
            fs2.Flush();
            fs2.Close();


I've got certificate with following information


Basic Constraints:

    Subject Type=End Entity
    Path Length Constraint=None

Authority Key Identifier:

    KeyID=37 7a 6e bb 14 01 30 66 e0 37 e5 10 f1 09 8c e1 b2 6c 6a 83






How can I create x509 certificate using Bouncy Castle in c#
===

I'm trying to generate an x509 certificate using Bouncy Castle in c#

the certificate I want to create have following information 
  

Basic Constraints:

    Subject Type=End Entity
    Path Length Constraint=None

Authority Key Identifier:

    KeyID=ca a8 92 7f a2 1c 81 46 cb 4a fc e4 c4 83 7d c3 41 9e f4 14
    Certificate Issuer:
         Directory Address:
          CN=test01
          OU=SIT
          O=Internet Widgits Pty Ltd
          S=Some-State
          C=AU
    Certificate SerialNumber=00 e9 db 3d d9 9f e1 1d 1e
  

which generated using openssl


but when I use following code

    var kpgen = new RsaKeyPairGenerator();
            kpgen.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), 1024));
            var cerKp = kpgen.GenerateKeyPair();

            IDictionary attrs = new Hashtable();
            attrs[X509Name.E] = user_email;
            attrs[X509Name.Name] = user_name;
            attrs[X509Name.UID] = account_user;
            attrs[X509Name.OU] = user_orgUnit;
            attrs[X509Name.O] = user_org;
            attrs[X509Name.C] = "TH";

            IList ord = new ArrayList();
            ord.Add(X509Name.E);
            ord.Add(X509Name.Name);
            ord.Add(X509Name.UID);
            ord.Add(X509Name.OU);
            ord.Add(X509Name.O);
            ord.Add(X509Name.C);

            X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

            certGen.SetSerialNumber(BigInteger.One);

            certGen.SetIssuerDN(new X509Name(ord, attrs));
            certGen.SetNotBefore(DateTime.Today.Subtract(new TimeSpan(1, 0, 0, 0)));
            certGen.SetNotAfter(DateTime.Today.AddDays(365));
            certGen.SetSubjectDN(new X509Name(ord, attrs));
            certGen.SetPublicKey(cerKp.Public);
            certGen.SetSignatureAlgorithm("SHA1WithRSA");

            X509Certificate x509 = certGen.Generate(cerKp.Private);

            System.Security.Cryptography.X509Certificates.X509Certificate x509_ = DotNetUtilities.ToX509Certificate(x509);
            System.Security.Cryptography.X509Certificates.X509Certificate2 x509__ = new System.Security.Cryptography.X509Certificates.X509Certificate2(x509_);
            
            certificate_data = x509__.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Cert);
            byte[] pvk_data = x509__.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Pfx, "password");
            
            //write certificate file
            FileStream fs = new FileStream(certificatePath, FileMode.CreateNew);
            fs.Write(certificate_data, 0, certificate_data.Length);
            fs.Flush();
            fs.Close();

            setPrivateKeyPath();

            FileStream fs2 = new FileStream(privateKeyPath, FileMode.CreateNew);
            fs2.Write(pvk_data, 0, pvk_data.Length);
            fs2.Flush();
            fs2.Close();


I've got certificate with following information


Basic Constraints:

    Subject Type=End Entity
    Path Length Constraint=None

Authority Key Identifier:

    KeyID=37 7a 6e bb 14 01 30 66 e0 37 e5 10 f1 09 8c e1 b2 6c 6a 83





