.NET
  Home arrow .NET arrow Smart Cards in .NET, Part 3
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Smart Cards in .NET, Part 3
By: Digvijay Chauhan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 32
    2004-11-15

    Table of Contents:
  • Smart Cards in .NET, Part 3
  • Two classes to rule them
  • Using the Library: The Demo
  • Smart card resource manager
  • CardCommand and SelectSmart
  • Source code for the library

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    Smart Cards in .NET, Part 3


    (Page 1 of 6 )

    In part II, we learned how to use platform invoke in .NET to access the raw APIs exported by the WinSCard.dll and use them in our own applications. That was an introduction explaining how we are going to going to access the native Smart Card APIs. In this article, we will learn how to write the library itself, by writing a managed wrapper for using smart cards in .NET.

    Support file for this article available here.


    Introduction

    In the last article, we learned how to use platform invoke in .NET to access the raw APIs exported by the WinSCard.dll and use them in our own applications. The basic example code for finding readers attached to system was also provided. That was just an introduction explaining how we are going to access the native Smart Card APIs, and now we shall write the library itself. If you have not read the last article, I’d recommend that you to skim though it once, just to understand the code in this article.

    The code for this library is written in C#, so I’d expect you to be familiar with the C# language. This is not compulsory, however, because equivalent code can be written in VB .NET--or any .NET compliant language for that matter. Because the library generated with our code is a Managed one, we can use it from any .NET compliant language. As for this library, the demo you’ll find is written in VB .NET.

    So without any further ado let’s get started with our library.

    Designing our classes

    To begin with the design of our classes for this library, we can look at the way the API’s in the WinSCard.dll are organized. They’re organized in the following categories:

    • Smart Card Database Query Functions
    • Smart Card Database Management Functions
    • Resource Manager Context Functions
    • Smart Card Tracking Functions
    • Smart Card and Reader Access Functions
    • Direct Card Access Functions

    The database query functions query the smart card database, and they can provide a list of smart cards that are supplied by a specific user, the interfaces, and the primary service provider of a specific smart card. These functions can be used to query the complete smart card database, or a part of it, by setting the resource manager context appropriately. The resource manager context is set by calling one of the Context functions prior to invoking a query function. The success of the called function also depends on the state of the Smart Card Service and the Security context of the calling application. Similarly, the database management functions manage the smart card database and update the database by using a specified resource manager context.

    The context functions, on other hand, establish and release the resource manager context, which is used by the database query and database management functions. Tracking functions allow for tracking smart cards within readers attached to the system. Most important are the reader access functions that connect to and communicate with a specific smart card, and manage the data structures for communicating and transferring data to/from the Smart Card. All protocol related details are also set and observed here. Since this is not a perfect world, one sometimes gets cards that are not ISO 7816 compliant, and to access such cards Direct Card access functions come to the rescue.

    More .NET Articles
    More By Digvijay Chauhan


       · Hi,I'm Digvijay .... the author of this article.Please do let me know how you...
       · Article looks very helpful. Will start looking and using them to suit our...
       · Hi,This is basically for managed code that is accessible from all .NET...
       · Hi, I am trying to access memory card (sle4428), as far as I know I need to use...
       · Hi,I jut provided the code to give an overview of how to go about it that is why...
       · Hi,This looks VERY useful. When can we expect the commercial library? I want to...
       · Hi ,You can expect that in March 2005 only.Regards,Digvijay
       · I am attempting to use the code provided and running into a little problem. I have...
       · Hi.In yur first article, what is the SCardLIB 1.0 component?In my Visual Basic...
       · Hi there,This code is quite interesting to me. It works great. Nice work. But I...
       · Hi, the library works fine in some readers, but with the next...
       · hi siri am Ramzy Ebiedi am using C#, ASP.Net VS2005i did test your...
       · Dear DigVijay,I would appreciate if you help me out....I'm developing an...
       · hi,I had this problem too, I tested my application with different cards,some...
       · Hi all,I'm very grateful to Mr. Digvijay for his article. Very interesting.I'm a...
       · Hi all, I'm very grateful to Mr. Digvijay for his article. Very interesting. I'm...
       · How to use your library to write a string like "hello word" and to read from the...
     

    .NET ARTICLES

    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...
    - Coding an AjaxPro.NET Based Search Engine fo...
    - Building an AjaxPro.NET Based Search Engine ...
    - Delving Deeper into Serialization with .NET
    - Serialization with .NET

    IBM developerWorks




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway