Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smart card reader development with .Net technologies

Does anyone know how to monitor the presence of smart card and read the UID value of the card?

Yes I tried lot of examples in web like

A Smart Card Framework for .NET

pcsc-sharp

Monitoring a Smartcard Reader

But No idea how to do it. I can detect the presence of a card and can get the UID separately, but no idea how to combine them in my application:( .

Help me

like image 651
iJay Avatar asked Nov 08 '13 15:11

iJay


People also ask

Which technology is used in smart cards?

A smart card includes an embedded integrated circuit chip that can be either a microcontroller chip with internal memory or a secured memory chip alone.

What are the two types of smart card readers?

Smart cards have two different types of interfaces: contact and contactless. Contact smart cards are inserted into a smart card reader, making physical contact with the reader. However, contactless smart cards have an antenna embedded inside the card that enables communication with the reader without physical contact.

How does a smart card reader work?

A smart card reader connected to a host computer, cloud computer, or any controlling terminal collects the information stored on the microprocessor chip of the smart card. Then, it sends such information received from the smart card back to the controlling terminal for immediate processing.


1 Answers

I figure it out. thought to share with anyone interested.

I used winscard.dll functions to access card data and communicate with PC.

Note that I used Mifare 1K cards as NFC tag and reader ACR 122u.

    private string getcardUID()//only for mifare 1k cards
    {
        string cardUID = "";
        byte[] receivedUID = new byte[256];
        Card.SCARD_IO_REQUEST request = new Card.SCARD_IO_REQUEST();
        request.dwProtocol = Card.SCARD_PROTOCOL_T1;
        request.cbPciLength = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Card.SCARD_IO_REQUEST));
        byte[] sendBytes = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 }; //get UID command      for Mifare cards
        int outBytes = receivedUID.Length;
        int status = Card.SCardTransmit(hCard, ref request, ref sendBytes[0], sendBytes.Length, ref request, ref receivedUID[0], ref outBytes);

        if (status != Card.SCARD_S_SUCCESS)
        {
            cardUID = "Error";
        }
        else
        {
            cardUID = BitConverter.ToString(receivedUID.Take(4).ToArray()).Replace("-", string.Empty).ToLower();
        }

        return cardUID;
    }

For anyone interested I've written step by step guide to achieve this in here.

Simple NFC reading system for windows

Enjoy!!!

like image 91
iJay Avatar answered Oct 23 '22 21:10

iJay