首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mifare Desfire / Mifare plus无法使用ACS ACR1252进行读取

Mifare Desfire / Mifare plus无法使用ACS ACR1252进行读取
EN

Stack Overflow用户
提问于 2021-04-17 21:09:06
回答 1查看 181关注 0票数 0

嗨,我是RFID阅读的新手。因此,我首先从github下载了pcsc sharp存储库。然后我尝试从普通的rfid标签中读取二进制数据,它工作得很完美,但下一步是从我认为是模拟的rfid标签中读取数据。射频识别标签控制器采用pn71501。在使用pcsc sharp的这个标记中,我无法读取除ATR和uid以外的任何数据。我试着用我的iPhone读取这个标签,它读取了它。那么我做错了什么呢?

我也尝试使用已经完成的软件,但它也不能读取它。

以下是我使用NFC工具得到的结果:

我使用的PS智能卡读卡器是ACS ACR1252

下面是我的代码:

代码语言:javascript
复制
using System;
using System.Text;
using System.Collections.Generic;
using PCSC;
using PCSC.Iso7816;

namespace Transmit {
    public class Program {
        public static void Main() {
            using (var context = ContextFactory.Instance.Establish(SCardScope.System)) {
                var readerNames = context.GetReaders();
                if (NoReaderFound(readerNames)) {
                    Console.WriteLine("You need at least one reader in order to run this example.");
                    Console.ReadKey();
                    return;
                }

                var readerName = ChooseRfidReader(readerNames);
                if (readerName == null) {
                    return;
                }

                String response = "";

                using (var rfidReader = context.ConnectReader(readerName, SCardShareMode.Shared, SCardProtocol.Any)) {
                  // for (byte i = 0x00; i < 0x47; i++) {
                        var apdu = new CommandApdu(IsoCase.Case3Extended, rfidReader.Protocol) {
                            CLA = 0xFF,
                            Instruction = (InstructionCode)0xB0,
                            P1 = 0x00,
                            P2 = 0x00,
                            Le = 0x10
                        };

                        using (rfidReader.Transaction(SCardReaderDisposition.Leave)) {
                            //Console.WriteLine("Retrieving the UID .... ");

                            var sendPci = SCardPCI.GetPci(rfidReader.Protocol);
                            var receivePci = new SCardPCI(); // IO returned protocol control information.

                            var receiveBuffer = new byte[256];
                            var command = apdu.ToArray();


                            var bytesReceived = rfidReader.Transmit(
                                sendPci, // Protocol Control Information (T0, T1 or Raw)
                                command, // command APDU
                                command.Length,
                                receivePci, // returning Protocol Control Information
                                receiveBuffer,
                                receiveBuffer.Length); // data buffer

                            var responseApdu =
                                new ResponseApdu(receiveBuffer, bytesReceived, IsoCase.Case3Extended, rfidReader.Protocol);

                        Console.WriteLine(String.Format("SW1: {0:X2} SW2: {1:X2}", responseApdu.SW1, responseApdu.SW2));
                        //if(responseApdu.DataSize > 0) {
                        //response += BitConverter.ToString(responseApdu.GetData()).Replace('-', ' ');
                          response += responseApdu.DataSize;
                           // }
                        }
                   // }
                }
                /*String[] devidedResponse = response.Split(' ');

                String stillResponse = "";

                bool notStarted = true;

                int skipBytes = 7;
                int onByte = 0;

                for(int i = 0; i < devidedResponse.Length; i++) {
                    if (devidedResponse[i] != "D1" && notStarted) {
                        continue;
                    } else if (onByte < skipBytes) {
                        notStarted = false;
                        onByte += 1;
                        continue;
                    } else if (devidedResponse[i] == "FE") {
                        break;
                    }

                    stillResponse += devidedResponse[i] + " ";
                }

                String res = stillResponse.Trim();

                string asciiCharString = "";

                var splitResult = res.Split(' ');

                foreach (string hexChar in splitResult) {
                    var byteChar = int.Parse(hexChar, System.Globalization.NumberStyles.HexNumber);
                    asciiCharString += (char)byteChar;
                }*/
                
                Console.WriteLine(response);
            }

            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();
        }

        private static string ChooseRfidReader(IList<string> readerNames) {
            // Show available readers.
            Console.WriteLine("Available readers: ");
            for (var i = 0; i < readerNames.Count; i++) {
                Console.WriteLine($"[{i}] {readerNames[i]}");
            }

            // Ask the user which one to choose.
            Console.Write("Which reader is an RFID reader? ");
            var line = Console.ReadLine();

            if (int.TryParse(line, out var choice) && choice >= 0 && (choice <= readerNames.Count)) {
                return readerNames[choice];
            }

            Console.WriteLine("An invalid number has been entered.");
            Console.ReadKey();
            return null;
        }

        private static bool NoReaderFound(ICollection<string> readerNames) =>
            readerNames == null || readerNames.Count < 1;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-04-18 21:23:56

我知道呀。我之前查过了。你能用文件资源管理器读卡吗?

像UART这样的硬件设备可以在三个不同的级别上读取

通过驱动程序查找硬件I/O address

  • Read/Write,
  1. 直接读写UART。在c#中使用开放式串行端口。驱动程序通过应用程序获取硬件I/O
  2. 读/写。应用程序执行上面的%1和/或%2。

您有一个正常工作的应用程序(编号为3),我不知道它使用的是方法1还是方法2。

使用读卡器,我会尽量让你的编程变得简单。如果你有一个API,最简单的方法是3。下一个最简单的方法是方法2,如果您安装了供应商驱动程序,则应该能够使用该方法。您应该会在设备管理器中看到设备。

要解锁卡(加密),您还需要安装证书,而不是卡附带的证书。文件资源管理器应该能够读/写卡。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67138537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档