Smart Cards in .NET
(Page 1 of 5 )
I’ll begin with an introduction to the smart card standards and especially the PC/SC specification, which I believe is the most widely accepted platform for developing and deploying Smart Card Applications and will move on to the problems encountered while accessing smart cards from the .NET environment. Concluding the article I’ll present the solution, which I adopted to resolve the problem and I hope that will help you with writing Smart Card Enabled applications in .NET.
Smart Cards have been around for many years now with the SUN® initiative of JavaCard™ technology to develop Smart Card solutions. They have created a lot of buzz in the IT world, especially the IT-enabled services sector. In this article we’ll be reading about the problems encountered while developing Smart Card enabled applications in .NET and then will see a solution for the same.
This solution may not be the best, but that it works just great for me! We’ll develop a pure, managed Smart Card Class library in future articles of this series.
Background:
Recently I needed to use a Smart Card reader from a C# application and I thought there would be support for it in some namespace in the FCL. But to my surprise there is no support for Smart Card access.
I tried to find some third party class libraries or Components which I could use but I ended up with some Delphi Components and a few articles explaining how to access WinSCard.dll Functions in C#. I tried that option but was unable to make the CLR work with the types, which vary in the native Win32 and the .NET environment. I couldn’t find anything that would satisfy all my requirements.
So I had two options to accomplish the task.
- To use P/Invoke and access the WinSCard.dll raw API, and
- To use the System.Runtime.InteropServices namespace which provides a collection of classes useful for accessing COM objects, and native APIs from .NET.
I tried the first option and realized that there would be a lot of trouble in this hit and miss method of identifying correct prototypes for the WinSCard.dll exported functions. So I was left with just one option: Writing a COM component for Smart Card access and later use the InteropServices to use it in .NET. It worked!
Next: The Solution >>
More .NET Articles
More By Digvijay Chauhan