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.
Next: Two classes to rule them >>
More .NET Articles
More By Digvijay Chauhan
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|