C# PSCS sharp:智能卡不响应发送数据(返回9F 0C-COMP 128)
这是我关于stack的第一个问题,请大家理解。我正在做一个关于智能卡和读卡器通信的项目。我有戴尔智能卡阅读器键盘和SIM卡。 我的项目是使用C#和pcsc-sharp.dll创建的 我的问题是卡对传输的位序列没有响应。下面,我添加了连续发送到智能卡的序列和响应C# PSCS sharp:智能卡不响应发送数据(返回9F 0C-COMP 128),c#,smartcard,apdu,sim-card,pcsc,C#,Smartcard,Apdu,Sim Card,Pcsc,这是我关于stack的第一个问题,请大家理解。我正在做一个关于智能卡和读卡器通信的项目。我有戴尔智能卡阅读器键盘和SIM卡。 我的项目是使用C#和pcsc-sharp.dll创建的 我的问题是卡对传输的位序列没有响应。下面,我添加了连续发送到智能卡的序列和响应 读卡器:戴尔智能卡读卡器键盘0 命令发送:A0 C000 00 20 回复:00 00 1F 3E 3F 00 01 00 0F 55 FF 01 15 B1 05 09 05 00 83 8A 83 8A 00 8A 00 00 00
- 回复:00 00 1F 3E 3F 00 01 00 0F 55 FF 01 15 B1 05 09 05 00 83 8A 83 8A 00 8A 00 00 00 00 00 00 00 90 00(可能没问题)
- 回复:9F22(可能没问题)
- 回答:9F 0C(可能没问题)
- 响应:9F 0C(这是错误,这不是对已发送数据的响应)
SCardContext context=new SCardContext();
建立(SCardScope.System);
//可用读者列表
string[]listOfReaders=context.GetReaders();
如果(listOfReaders.Length您可能也需要研究一下。这种行为很奇怪,因为卡应该返回SRES/Kc而不是另一个9F 0C
。。祝您好运!非常感谢您的回答。不幸的是,传输函数有错误的参数。所以您的问题解决了吗?我在您的帖子中检查了片段中的参数,它看到了我会纠正我的。
SCardContext context = new SCardContext();
context.Establish(SCardScope.System);
//Lista of available readers
string[] listOfReaders = context.GetReaders();
if (listOfReaders.Length <= 0)
{
throw new PCSCException(SCardError.NoReadersAvailable);
}
else
{
Console.WriteLine("Reader: " + listOfReaders[0]);
}
SCardReader reader = new SCardReader(context);
SCardError error = reader.Connect(listOfReaders[0], SCardShareMode.Exclusive, SCardProtocol.T0 | SCardProtocol.T1);
CheckErr(error);
IntPtr transmissionProtocol;
switch (reader.ActiveProtocol)
{
case SCardProtocol.T0:
transmissionProtocol = SCardPCI.T0;
break;
case SCardProtocol.T1:
transmissionProtocol = SCardPCI.T1;
break;
default:
throw new PCSCException(SCardError.ProtocolMismatch, reader.ActiveProtocol.ToString());
}
byte[] receivedData = new byte[256];
byte[] commandIntroduceYourself = new byte[] { 0xA0, 0xC0, 0x00, 0x00, 0x20 };
Console.Write("->");
for (int i = 0; i < commandIntroduceYourself .Length; i++)
{
Console.Write("{0:X2} ", start[i]);
}
error = czytnik.Transmit(transmissionProtocol, commandIntroduceYourself , ref receivedData);
Console.WriteLine();
Console.Write("<-");
for (int i = 0; i < receivedData.Length; i++)
{
Console.Write("{0:X2} ", receivedData[i]);
}
Console.WriteLine();
//This command below was required by the professor. I don't know why...
byte[] commandNext = new byte[] { 0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20 };
Console.Write("->");
for (int i = 0; i < commandNext.Length; i++)
{
Console.Write("{0:X2} ", commandNext[i]);
}
error = czytnik.Transmit(transmissionProtocol, commandNext, ref receivedData);
Console.WriteLine();
Console.Write("<-");
for (int i = 0; i < receivedData.Length; i++)
{
Console.Write("{0:X2} ", receivedData[i]);
}
Console.WriteLine();
int amountOfDataToRand = 16;
//This is my function, never mind
string data = Randomize.RandomData(amountOfDataToRand);
byte[] dataSendToCard = Randomize.StringToByteArray(data);
byte[] newArray = new byte[dataSendToCard.Length + 5];
//Below is sequence that should be added to data
dataSendToCard.CopyTo(newArray, 5);
newArray[0] = 0xA0;
newArray[1] = 0x88;
newArray[2] = 0x00;
newArray[3] = 0x00;
newArray[4] = 0x10;
dataSendToCard = newArray;
Console.WriteLine("\nData send: ");
for (int i = 0; i < dataSendToCard.Length; i++)
{
Console.Write("{0:X2} ", dataSendToCard[i]);
}
Console.WriteLine();
error = czytnik.Transmit(transmissionProtocol, dataSendToCard, ref receivedData);
CheckErr(error);
Console.Write("Data received: ");
for (int i = 0; i < receivedData.Length; i++)
{
Console.Write("{0:X2} ", receivedData[i]);
}
Console.WriteLine();
byte[] commandGetResponse = new byte[] { 0xA0, 0xC0, 0x00, 0x00,0x0c };
Console.Write("->");
for (int i = 0; i < commandGetResponse.Length; i++)
{
Console.Write("{0:X2} ", commandGetResponse[i]);
}
error = czytnik.Transmit(transmissionProtocol, commandGetResponse, ref receivedData);
Console.WriteLine();
Console.Write("<-");
for (int i = 0; i < receivedData.Length; i++)
{
Console.Write("{0:X2} ", receivedData[i]);
}
Console.WriteLine();