【发布时间】:2021-07-12 06:22:27
【问题描述】:
您好,我是 RFID 读取的新手。所以首先我从 github 下载了 pcsc sharp 存储库。然后我尝试从常见的 rfid 标签中读取二进制文件,它工作得很好,但下一步是从我认为模拟的 rfid 标签中读取数据。 RFID标签控制器是pn71501。从这个使用 pcsc sharp 的标签中,我无法读取除 ATR 和 uid 之外的任何数据。我试图用我的 iPhone 读取这个标签,它读取了它。那我做错了什么?
我也尝试使用已经完成的软件,但它也无法读取。
这是我使用 NFC 工具得到的结果:
我使用的 PS 智能卡读卡器是 ACS ACR1252
这是我的代码:
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;
}
}
【问题讨论】:
-
智能卡已加密,您必须先解锁卡才能读取。首先使用文件资源管理器读取卡。该卡将保持解锁状态。然后运行您的应用程序。如果应用程序有效,那么问题是您的应用程序需要解锁卡。
-
@jdweng,我如何使用文件资源管理器读取卡片?我什至没有设备中的阅读器
-
有不同类型的卡片。大多数卡作为文件系统安装在您的机器上。所以文件资源管理器可以读取卡。卡需要安装,所以你首先从制造商安装卡的驱动程序。当您将卡放入读卡器时,驱动程序会自动安装卡。该过程类似于将 USB 设备(如记忆棒)放入机器中。记忆棒作为文件系统安装。其他 USB 设备作为串行设备安装。硬件设备具有指示设备类型的标头。
-
ACS ACR 1252 是一款 USB 读卡器。所以读卡器的驱动程序安装在机器上,看起来像一个可移动的硬盘驱动器。读卡器具有与您安装在机器上的驱动程序通信的硬件/软件。所以卡信息被串行发送到您机器中的驱动程序,驱动程序使串行数据看起来像一个文件系统。
-
@jdweng,我只能在文件资源管理器中看到的硬盘是我的两个硬盘,除此之外别无其他
标签: c# rfid smartcard-reader pcsc acr1252