.NET
  Home arrow .NET arrow Page 5 - Smart Cards in .NET, Part 3
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 
Moblin 
JMSL Numerical Library 
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 / 33
    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


    Smart Cards in .NET, Part 3 - CardCommand and SelectSmart


    (Page 5 of 6 )

    The CardCommand Class will allow you to create and use the ISO-7816 compliant APDUs and the SCUtil helper class can help you convert strings to byte arrays for Transmitting and converting the Smart Card response from a byte array to String for display in the UI or console. Other enums often will be used as function parameters and are self-explanatory.

    Another feature is the SelectSmartCard Dialog, which lets the user select a reader from the system readers through UI. To use it, just call this static method from the SCReaser class. Also, take a look at the types you’ll be dealing with in the listing for file (can be found in the source code) Types.cs:

    using System;
    using System.Runtime.InteropServices;

    namespace SCLib
    {
     public enum SCardAccessMode
     {
      Direct = 3,
      Exclusive = 1,
      Shared = 2
     }
     public enum SCardResponseCode
     {
      Cancelled = 2,
      InsufficientBuffer = 8,
      InvalidHandle = 3,
      InvalidParameter = 4,
      InvalidValue = 0x11,
      NoMemory = 6,
      NoService = 0x1d,
      NoSmartCard = 12,
      NotReady = 0x10,
      NotTransacted = 0x16,
      ProtoMismatch = 15,
      ReaderUnavailable = 0x17,
      RemovedCard = 0x69,
      ResetCard = 0x68,
      ServiceStopped = 30,
      SharingViolation = 11,
      SystemCancelled = 0x12,
      Timeout = 10,
      UnknownCard = 13,
      UnknownReader = 9,
      UnpoweredCard = 0x67,
      UnresponsiveCard = 0x66,
      UnsupportedCard = 0x65
     }
     
     public enum SCardContextScope
     {
      System = 2,
      Terminal = 1,
      User = 0
     }
     
     public enum SCardReaderState
     {
      Absent = 1,
      Negotiable = 5,
      Powered = 4,
      Present = 2,
      Specific = 6,
      Swallowed = 3,
      Unknown = 0
     }

     public enum SCardReaderCapability
     {
      ATRString = 0x90303,
      ChannelID = 0x20110,
      Characteristics = 0x60150,
      CurrentBWT = 0x80209,
      CurrentCLK = 0x80202,
      CurrentCWT = 524810,
      CurrentD = 0x80204,
      CurrentEBCEncoding = 0x8020b,
      CurrentF = 0x80203,
      CurrentIFSC = 0x80207,
      CurrentIFSD = 0x80208,
      CurrentIOState = 0x90302,
      CurrentN = 0x80205,
      CurrentProtocolType = 0x80201,
      CurrentW = 0x80206,
      DeviceFriendlyName = 0x7fff0003,
      DeviceInUse = 0x7fff0002,
      DeviceSystemName = 0x7fff0004,
      DeviceUnit = 0x7fff0001,
      EscAuthRequest = 0x7a005,
      EscCancel = 0x7a003,
      EscReset = 0x7a000,
      ExtendedBWT = 0x8020c,
      ICCInterfaceStatus = 0x90301,
      ICCPresence = 0x90300,
      ICCTypePerATR = 0x90304,
      MaxInput = 0x7a007,
      PerfBytesTransmitted = 0x7ffe0002,
      PerfNumTransmissions = 0x7ffe0001,
      PerfTransmissionTime = 0x7ffe0003,
      PowerMgmtSupport = 0x40131,
      ProtocolDefaultCLK = 0x30121,
      ProtocolDefaultDataRate = 0x30123,
      ProtocolMaxCLK = 0x30122,
      ProtocolMaxDataRate = 196900,
      ProtocolMaxIFSD = 0x30125,
      ProtocolTypes = 0x30120,
      SuppressT1IFSRequest = 0x7fff0007,
      UserAuthInputDevice = 0x50142,
      UserToCardAuthDevice = 328000,
      VendorIFDSerialNo = 0x10103,
      VendorIFDType = 0x10101,
      VendorIFDVersion = 0x10102,
      VendorName = 0x10100
     }

     [Flags]
     public enum SCardProtocolIdentifiers
     {
      Default = -2147483648,
      Optimal = 0,
      Raw = 0x10000,
      T0 = 1,
      T1 = 2,
      Undefined = 0
     }
     
     [Flags]
     public enum SCStates
     {
      AtrMatch = 0x40,
      Changed = 2,
      Empty = 0x10,
      Exclusive = 0x80,
      Ignore = 1,
      InUse = 0x100,
      Mute = 0x200,
      Present = 0x20,
      Unavailable = 8,
      Unaware = 0,
      Unknown = 4,
      Unpowered = 0x400
     }
     
     [StructLayout(LayoutKind.Sequential)]
     public struct SCStateInfo
     {
      public string sReaderName;
      public SCStates nCurrentState;
      public SCStates nEventState;
      public byte[] vbATR;
     }
     
        [Flags]
     public enum SCardMechanicalCharacteristics
     {
      Captures = 4,
      Ejects = 2,
      None = 0,
      Swallows = 1
     }
     
     public enum SCardDisposition
     
    {
      Confiscate = 4,
      EjectCard = 3,
      LeaveCard = 0,
      ResetCard = 1,
      UnpowerCard = 2
     }
     public enum SCardControlCodes
     {
      Absent = 0x31002c,
      Confiscate = 3211280,
      Eject = 0x310018,
      GetAttribute = 0x310008,
      GetLastError = 0x31003c,
      GetPerfCntr = 0x310040,
      Power = 0x310004,
      Present = 0x310028,
      Protocol = 0x310030,
      Read = 0x310020,
      SetAttribute = 0x31000c,
      State = 3211320,
      Swallow = 0x31001c,
      Transmit = 0x310014,
      Write = 3211300
     }

     public enum SCardChannelType
     {
      IDE = 0x10,
      Keyboard = 4,
      Parallel = 2,
      PCMCIA = 0x40,
      SCSI = 8,
      Serial = 1,
      Unknown = 0,
      USB = 0x20,
      Vendor = 240
     }
     
     [Flags]
     public enum SCardAuthDevices
     {
      Display = 0x80,
      EncryptedInput = 0x8000,
      Fingerprint = 8,
      Image = 0x20,
      Keyboard = 4,
      NoDevices = 0,
      Numeric = 2,
      ReservedFU = 1,
      Retinal = 0x10,
      Voice = 0x40
     }
     

     public enum SCLibExceptionCode
     {
      CardCommunicationError = 2,
      CardWithdrawn = 1,
      DriverError = 3,
      DriverException = 4,
      DriverIncompatible = 5,
      InvalidAPDU = 0
     }

    }

    I believe this will be more than enough to get you started writing applications using the library, or maybe writing your own version.

    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

    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - 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...





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