Current location - Trademark Inquiry Complete Network - Overdue credit card - Method for read ic card chip by computer
Method for read ic card chip by computer
1, reading

We need an external NFC card reader so that Windows can read the contents of the NFC card.

For special reasons, we chose Sony rc-s380 NFC card reader. Related introduction

We need to download and install the NFC port software, so that we can use the NFC reader smoothly.

After installation, you need to go to Github to get a. Net package of NFC port software: tijins/NfcLib.

After decompressing and running nfc_lib_sample, we can see such a WindowFrom program.

Because the card type we want to read now tries MIFARE, so we check the correct check box, other settings remain unchanged, and click the three orange box buttons above in turn.

You can see the hexadecimal string data of the first block in the direction indicated by the red arrow.

In order to read all the block/page information of the card, we slightly modify the code of btRead_Click to:?

Private void btRead_Click (object sender, EventArgs e)

{

Byte block = (bytes) nudBlock. Value; try { byte[]data = null;

Data = new byte [NfcLib. MF _ BLOCK _ LENGTH]; If (the card is Mifare)

{

StringBuilder readSB = new StringBuilder(); For (byte I = 0;; I & lt45; I++)// My current card contains 45 pieces per page {

((Mifare) card) Read(i,data,0);

readSB。 AppendLine (utility. ByteToHex (data, 0, data. Length));

}

tbRead。 Text = readSB。 ToString();

}

} catch (exception ex)

{

MessageBox。 Display (for example. Message);

}

}

There is a small regret. If you don't connect an NFC reader, starting the app will throw an exception. If you have started the app and then pulled it out and inserted it into the NFC reader, you can't read the card unless you restart or reinitialize the app. This needs a little improvement.

2. Analysis

According to the above steps, we got the information of a card as follows:

04 C9 02 47 0A C9 5A 84 1D 48 00 00 e 10 10 12 00 0A C9 5A 84 1D 48 00 00 e 10 10 12 00 00 03 a0c

1D 48 00 00 e 10 12 00 0 1 03 A0 0C 34 03 0F d 1

e 1 10 12 00 0 1 03 A0 0C 34 03 0F d 1 0B 54 02 0 1 03 A0 0C 34 0F d 1 0 1 0 1 0B 54 02 65656538+0 0e 32 30 34 0F d 1 065438 00 3 1 38 3 1 30 32 35 FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

(omitted below ...)

So, let's move a little bit:

04 C9 02 47 0A C9 5A 84 1D 48 00 00 e 10 10 12 00 0A C9 5A 84 1D 48 00 00 e 10 10 12 00 00 03 a0c

1D 48 00 00 e 10 12 00 0 1 03 A0 0C 34 03 0F d 1

e 1 10 12 00 0 1 03 A0 0C 34 03 0F d 1 0 1 0B 54 02

0 1 03 A0 0C 34 03 0F d 1 0 1 0B 54 02 65 6E 32 30

34 03 0F d 1 0 1 0B 54 02 65 6E 32 30 3 1 38 3 1 30

0 1 0B 54 02 65 6E 32 30 3 1 38 3 1 30 32 35 FE 00

65 6E 32 30 3 1 38 3 1 30 32 35 FE 00 00 00 00

3 1 38 3 1 30 32 35

32 35 FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

As you can see, only the first column in each row is the label information we need.

04 C9 02 470 a C9 5A 84 1D 48 00 00e 1 10 10 02 00

0 1 03 A0 0C?

34 03 0F d 10 1 0B 54 0265 6E 32 303 1 38 3 1 3032 35 FE 00

The first four lines are the UID and manufacturer information of the card. We only need to care about the data for the second half of the year.

0 1 (label: locked TLV)03 (length: 3 bytes)

A0 0C 34 (value: information about the position and function of the lock byte) 03 (label: NDEF message TLV)

0F (length: 15 bytes)

D1010b54 02 65 6e32 303138 3130 32 35 Fe (label: terminator TLV;; No length field) 00

Therefore, we get the ndef message: d1010b5402656e3230313831303235.

NDEF message:

D 1 (record header byte 1)0 1 (type length: 1 byte)

0B (payload length: 1 1 byte) 54 (type: "t") 02 65 6e32 303138 3130 32 35 (payload field)

Let's analyze the most critical payload fields as follows:

Payload field: 02 (status byte: the text is encoded in UTF-8, and the language code is 2 bytes long) 65 6E (language code: "en") 32 303138 3130 32 35 (text: "2018/kloc).

Online tools can be used to verify "32 30 3 1 38 3 1 30 32 35".

Finally, the above steps are realized by writing C# in the following way (not all Mifare cards are guaranteed to be applicable):

Private string getnfctag (list <: byte[]& gt; cardContentList)

{

List & ltbyte & gtcardBytes = new list & ltbyte & gt (); Foreach (byte[] rowCardContent in cardcontentlist)

{

cardBytes。 AddRange(rowCardContent。 Take (4));

} byte[] cardUid = cardBytes。 Take (8). to array(); string cardUidStr = Utility。 ByteToHex(cardUid,0,cardUid。 Length); byte[] cardMaker = cardBytes。 Skip (8). Take (8). to array(); String cardMakerStr = utility. ByteToHex(cardMaker,0,cardMaker。 Length); byte[] memoryBytes = cardBytes。 Skip (16). to array(); byte lockControlByte = memory bytes[0]; byte lock bytecount = memory bytes[ 1]; //How many bytes is the lock byte?

byte[] lockBytes = memoryBytes。 Skip (2). Take(lockByteCount)。 to array(); int nedfLengthByteIndex = 1+lock bytecount+ 1+ 1; byte ndef length = memory bytes[nedfLengthByteIndex]; If(ndef length = = 0)// flag is empty.

Returns a string. Empty; byte[] ndefBytes = memoryBytes。 skip(nedfLengthByteIndex+ 1)。 Take (ndefLength). to array(); byte payload header = ndefBytes[0]; byte payload type length = ndefBytes[ 1]; byte payload length = ndefBytes[2]; byte[] payloadType = ndefBytes。 Skip (3). Take(payloadTypeLength)。 to array(); byte[] payloadBytes = ndefBytes。 Skip (3+payloadType. Length). Take(payloadLength)。 to array(); byte language codelength = payload bytes[0]; Byte[] languageCode = payload byte. Skip (1). Take(languageCodeLength)。 to array(); Byte[] tag = payload byte. Skip (1+languageCode. Length). take(payload length-language code。 Length-1). to array(); String tagHex= utility. ByteToHex (tag, 0, tag. Length); String tagStr = encoding. UTF8.GetString (label); Return to tagStr

}