Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Smart Card Framework for .NET

, 20 Feb 2013
Describes a framework to use the PCSC Smart Card API with .NET.
smartcardapi_demo.zip
smartcardapi_doc.zip
smartcardapi_doc
banner.jpg
darkcorner.jpg
GemCard
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
smartcardapi_source.zip
Smartcard_API
DemoSCFmwk
Properties
GemCardEx
GemCardEx.aps
GemCardEx.def
GemCardEx.rgs
GemCardEx.suo
GemCardEx.vcproj.CORUSCANT.han.user
GemCardEx.vcproj.vspscc
GemCardExps.def
Release
GemCardEx.dll
SCardDatabaseEx.rgs
Smartcard Framework 2005.suo
GemCard
GemCard.csproj.user
SmartcardFrameworkWithWCFSCardService.zip
SmartcardFramework
DemoSCardService
bin
Release
obj
Properties
Service References
SCardNPService
configuration.svcinfo
configuration91.svcinfo
DemoSCardService.SCardNPService.APDUResponse.datasource
Reference.svcmap
service.wsdl
SCardService
configuration.svcinfo
configuration91.svcinfo
DemoSCardService.SCardService.APDUResponse.datasource
Reference.svcmap
service.wsdl
SCardServiceHost
bin
obj
Properties
Settings.settings
Smartcard Framework 2010.suo
Smartcard Framework 2010.v11.suo
Smartcard_API
DemoSCFmwk
bin
x86
obj
x86
Properties
GemCard
bin
x64
x86
GemCard.csproj.user
obj
x64
x86
SmartCardPlayer
bin
x86
obj
x86
Properties
Smartcard_Test
ApduExchange
ApduExchange.csproj.user
App.ico
bin
x86
obj
x86
Thumbs.db
GSMHelper
bin
x86
obj
x86
Properties
ReadPhonebook
bin
x86
obj
x86
Properties
Settings.settings
ReadPhonebook.csproj.user
SmartcardService
bin
obj
Properties
SmartcardService.csproj.user
Smartcard_Framework_2010.zip
Smartcard_Framework_2010
Smartcard Framework 2010.suo
Smartcard_API
DemoSCFmwk
DemoSCFmwk.csproj.user
Properties
GemCard
GemCard.csproj.user
SmartCardPlayer
Properties
Smartcard_Test
ApduExchange
ApduExchange.csproj.user
App.ico
GSMHelper
Properties
ReadPhonebook
Properties
Settings.settings
ReadPhonebook.csproj.user
Smartcard_Framework_64.zip
Smartcard_Framework
Smartcard_API
DemoSCFmwk
Properties
GemCard
GemCard.csproj.user
SmartCardPlayer
Properties
Smartcard_Test
ApduExchange
ApduExchange.csproj.user
App.ico
GSMHelper
Properties
ReadPhonebook
Properties
Settings.settings
ReadPhonebook.csproj.user
using System;
using System.Collections.Generic;
using System.Text;

namespace GemCard
{
    /// <summary>
    /// This class is used to update a set of parameters of an APDUCommand object
    /// </summary>
    public class APDUParam
    {
        byte
            m_bClass = 0,
            m_bChannel = 0,
            m_bP2 = 0,
            m_bP1 = 0;
        byte[] m_baData = null;
        short m_nLe = -1;
        bool 
            m_fUseP1 = false,
            m_fUseP2 = false,
            m_fChannel = false,
            m_fData = false,
            m_fClass = false,
            m_fLe = false;

        #region Constructors
        public APDUParam()
        {
        }

        /// <summary>
        /// Copy constructor (used for cloning)
        /// </summary>
        /// <param name="param"></param>
        public APDUParam(APDUParam param)
        {
            // Copy field
            if (param.m_baData != null)
                param.m_baData.CopyTo(m_baData, 0);
            m_bClass = param.m_bClass;
            m_bChannel = param.m_bChannel;
            m_bP1 = param.m_bP1;
            m_bP2 = param.m_bP2;
            m_nLe = param.m_nLe;

            // Copy flags field
            m_fChannel = param.m_fChannel;
            m_fClass = param.m_fClass;
            m_fData = param.m_fData;
            m_fLe = param.m_fLe;
            m_fUseP1 = param.m_fUseP1;
            m_fUseP2 = param.m_fUseP2;
        }

        public APDUParam(byte bClass, byte bP1, byte bP2, byte[] baData, short nLe)
        {
            this.Class = bClass;
            this.P1 = bP1;
            this.P2 = bP2;
            this.Data = baData;
            this.Le = (byte)nLe;
        }
        #endregion

        /// <summary>
        /// Clones the current APDUParam instance
        /// </summary>
        /// <returns></returns>
        public APDUParam Clone()
        {
            return new APDUParam(this);
        }

        /// <summary>
        /// Resets the current instance, all flags are set to false
        /// </summary>
        public void Reset()
        {
            m_bClass = 0;
            m_bChannel = 0;
            m_bP2 = 0;
            m_bP1 = 0;

            m_baData = null;
            m_nLe = -1;

            m_fUseP1 = false;
            m_fUseP2 = false;
            m_fChannel = false;
            m_fData = false;
            m_fClass = false;
            m_fLe = false;
        }

        #region Flags properties
        public bool UseClass
        {
            get { return m_fClass; }
        }

        public bool UseChannel
        {
            get { return m_fChannel; }
        }

        public bool UseLe
        {
            get { return m_fLe; }
        }

        public bool UseData
        {
            get { return m_fData; }
        }

        public bool UseP1
        {
            get { return m_fUseP1; }
        }

        public bool UseP2
        {
            get { return m_fUseP2; }
        }
        #endregion

        #region Parameter properties
        public byte P1
        {
            get { return m_bP1; }

            set
            {
                m_bP1 = value;
                m_fUseP1 = true;
            }
        }

        public byte P2
        {
            get { return m_bP2; }
            set
            {
                m_bP2 = value;
                m_fUseP2 = true;
            }

        }

        public byte[] Data
        {
            get { return m_baData; }
            set
            {
                m_baData = value;
                m_fData = true;
            }
        }

        public byte Le
        {
            get { return (byte)m_nLe; }
            set
            {
                m_nLe = value;
                m_fLe = true;
            }
        }

        public byte Channel
        {
            get { return m_bChannel; }
            set
            {
                m_bChannel = value;
                m_fChannel = true;
            }
        }

        public byte Class
        {
            get { return m_bClass; }
            set
            {
                m_bClass = value;
                m_fClass = true;
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

orouit
Architect Consistel - Singapore
Singapore Singapore
Software Architect, COM, .NET and Smartcard based security specialist.
 
I've been working in the software industry since I graduated in Electrical and Electronics Engineering. I chose software because I preferred digital to analog.
 
I started to program with 6802 machine code and evolved to the current .NET technologies... that was a long way.
 
For more than 20 years I have always worked in technical positions as I simply like to get my hands dirty and crack my brain when things don't go right!
 
After 12 years in the smart card industry I can claim a strong knowledge in security solutions based on those really small computers! I'm currently back in the business to design the licensing system for the enterprise solution I'm currenly working on, using a .NET smart card (yes they can run .NET CLR!)
 
View my profile on LinkedIn
 
You can contact me for professional consulting by using the forum.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 20 Feb 2013
Article Copyright 2006 by orouit
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid