Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:35:25+00:00 2026-06-07T18:35:25+00:00

We have a valid PKCS#10 Certificate Request generated on the Client using CertEnroll. Now

  • 0

We have a valid PKCS#10 Certificate Request generated on the Client using CertEnroll.

Now we need to sign it and return the result to the Client, where CertEnroll will handle the local Certificate Store stuff.

This is a B2B application and the root signing certificate will be self-generated or we can use our existing Thawte SSL cert.

The Server (2008) does not have Active Directory running and we don’t want to create a stand-alone signing infrastructure/service for this unless absolutely necessary. There is no need for revocation etc. – we want to do it programmatically.

I would be happy to use the BouncyCastle Library however the C# lib lacks any meaningful documentation and while the original Java docs are admittedly similar the C# implementation is different enough to have left me more than a little confused.

Is anyone aware of (or have) sample C# (or VB) code or a known-relaible link to same, using BouncyCastle or for that matter the native .Net classes ?

Any assistance in getting this thing done would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:35:26+00:00Added an answer on June 7, 2026 at 6:35 pm

    This proved an interesting exercise to say the least 🙂

    We used both BouncyCastle and the .Net certificate objects. The solution still has !much! room for improvement, but it does in fact work.

    The guts of it (Cert Gen) are below. When we get here the CSR has already been generated on the client and and when we leave the resulting certificate is installed by Client-side code (see this blog for client-side workings.)

    Again, I am not offering this as a Finished Product but hopefully of some value to those facing the same task. Happy Encrypting 🙂

            // Jul 10, 2012 see
            // http://social.technet.microsoft.com/Forums/en-NZ/winserversecurity/thread/45781b46-3eb7-4715-b877-883bf0dc2ae7
            // instaed of CX509CertificateRequestPkcs10 csr = new CX509CertificateRequestPkcs10(); use:
            IX509CertificateRequestPkcs10 csr = (IX509CertificateRequestPkcs10)Activator.CreateInstance(Type.GetTypeFromProgID("X509Enrollment.CX509CertificateRequestPkcs10"));
            csr.InitializeDecode(csrText, EncodingType.XCN_CRYPT_STRING_BASE64);
            csr.CheckSignature(Pkcs10AllowedSignatureTypes.AllowedKeySignature);
    
            //get Bouncy CSRInfo Object
            Trace.Write("get Bouncy CSRInfo Object");
            Byte[] csrBytes = Convert.FromBase64String(csrText);
            CertificationRequestInfo csrInfo = CertificateTools.GetCsrInfo(csrBytes);
            SubjectPublicKeyInfo pki = csrInfo.SubjectPublicKeyInfo;
    
            //pub key for the signed cert
            Trace.Write("pub key for the signed cert");
            AsymmetricKeyParameter publicKey = PublicKeyFactory.CreateKey(pki);
    
            // Build a Version1 (No Extensions) Certificate
            DateTime startDate = DateTime.Now;
            DateTime expiryDate = startDate.AddYears(100);
            BigInteger serialNumber = new BigInteger(32, new Random());
    
            Trace.Write("Build a Version1 (No Extensions) Certificate");
            X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
            string signerCN = ConfigurationManager.AppSettings["signerCN"].ToString();
            X509Name dnName = new X509Name(String.Format("CN={0}", signerCN));
            X509Name cName = new X509Name(csr.Subject.Name);
            certGen.SetSerialNumber(serialNumber);
            certGen.SetIssuerDN(dnName);
            certGen.SetNotBefore(startDate);
            certGen.SetNotAfter(expiryDate);
            certGen.SetSubjectDN(cName);
            certGen.SetSignatureAlgorithm("SHA1withRSA");
            certGen.SetPublicKey(publicKey);
    
            //get our Private Key to Sign with
            Trace.Write("get our Private Key to Sign with");
            X509Store store = new X509Store(StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            string signerThumbprint = ConfigurationManager.AppSettings["signerThumbprint"].ToString();
            X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
            X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByThumbprint, signerThumbprint, false);
            X509Certificate2 caCert = fcollection[0];
    
            Trace.Write("Found:" + caCert.FriendlyName);
            Trace.Write("Has Private " + caCert.HasPrivateKey.ToString());
            Trace.Write("Key Size " + caCert.PrivateKey.KeySize.ToString());
    
            //Get our Signing Key as a Bouncy object
            Trace.Write("Get our Signing Key as a Bouncy object from key ");
            AsymmetricCipherKeyPair caPair = DotNetUtilities.GetKeyPair(caCert.PrivateKey);
    
            //gen BouncyCastle object
            Trace.Write("gen BouncyCastle object");
            Org.BouncyCastle.X509.X509Certificate cert = certGen.Generate(caPair.Private);
    
            //convert to windows type 2 and get Base64 String
            Trace.Write("convert to windows type 2 and get Base64 String");
            X509Certificate2 cert2 = new X509Certificate2(DotNetUtilities.ToX509Certificate(cert));
            byte[] encoded = cert2.GetRawCertData();
            string certOutString = Convert.ToBase64String(encoded);
    
            //output to the page (hidden)
            Certificate.Value = certOutString;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website developed using ASP.NET MVC3. I now want to expose a
I have valid JPG files and now I want to load them into a
I'm trying to write a query to tell me which orders have valid promocodes.
Is there any way to enclose <style> tags within <body> and still have valid
I have a valid reason for wanting to do this, but it's a long
I have a valid SAML 2 token from my application IdP: When I try
I have a valid link that goes to a picture located on my web
I have a valid developer profile. I could run and debug my app in
My problem involves checking if I have a valid database connection before reading from
I have a text field and am looking to have if be valid for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.