This is a mirror of official site: http://jasper-net.blogspot.com/

How to request an smartcard logon cert programmatically (C#)

| Thursday, July 29, 2010
Hi all,

The other day I created this C# sample which shows how to request an smartcard logon cert to a CA. It is based on this other sample: How to create a certificate request with CertEnroll and .NET (C#).

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

//  Add the CertEnroll namespace
using CERTENROLLLib;
using CERTCLIENTLib;

namespace CATest
{
   public partial class Form1 : Form
   {
       private const int CC_DEFAULTCONFIG = 0;
       private const int CC_UIPICKCONFIG = 0x1;
       private const int CR_IN_BASE64 = 0x1;
       private const int CR_IN_FORMATANY = 0;
       private const int CR_IN_PKCS10 = 0x100;
       private const int CR_DISP_ISSUED = 0x3;
       private const int CR_DISP_UNDER_SUBMISSION = 0x5;
       private const int CR_OUT_BASE64 = 0x1;
       private const int CR_OUT_CHAIN = 0x100;

       public Form1()
       {
           InitializeComponent();
       }

       // Create request
       private void createRequestButton_Click(object sender, EventArgs e)
       {
           //  Create all the objects that will be required
           CX509CertificateRequestPkcs10 objPkcs10 = new CX509CertificateRequestPkcs10Class();
           CX509PrivateKey objPrivateKey = new CX509PrivateKeyClass();
           CCspInformations objCSPs = new CCspInformationsClass();
           CX500DistinguishedName objDN = new CX500DistinguishedNameClass();
           CX509Enrollment objEnroll = new CX509EnrollmentClass();
           CObjectIds objObjectIds = new CObjectIdsClass();
           CObjectId objObjectId = new CObjectIdClass();
           CX509ExtensionKeyUsage objExtensionKeyUsage = new CX509ExtensionKeyUsageClass();
           CX509ExtensionEnhancedKeyUsage objX509ExtensionEnhancedKeyUsage = new CX509ExtensionEnhancedKeyUsageClass();
           CX509ExtensionTemplateName objExtensionTemplate = new CX509ExtensionTemplateName();
           string strRequest;

           try
           {
               requestText.Text = "";

Read more: Decrypt my World

Posted via email from .NET Info

0 comments: