我正在使用C#读取EMV卡的应用程序。我使用Winscard.dll。 我建立了conncetion - 选择读者 - 连接到卡并获得ATR。 但是当发送命令Slecetd应用程序使用AID列表时,我没有收到任何数据,我预计会收到SW1SW2为61XX(其中XX的数据长度) 我发送命令为00A4040007A0000000031010。
代码是:
// Private/Internal Types
[StructLayout(LayoutKind.Sequential)]
internal class SCARD_IO_REQUEST
{
internal uint dwProtocol;
internal int cbPciLength;
public SCARD_IO_REQUEST()
{
dwProtocol = 0;
}
}
public static IntPtr GetPciT0()
{
IntPtr handle = LoadLibrary("Winscard.dll");
IntPtr pci = GetProcAddress(handle, "g_rgSCardT0Pci");
FreeLibrary(handle);
return pci;
}
// public static byte[] GetSendBuffer(string cla, string ins , string p1 ,string p2 , string lc,string body )
public byte[] GetSendBuffer()
{
// Select application 00A4040007A0000000031010
string cla = "00";
string ins = "A4";
string p1 = "04";
string p2 = "00";
string lc = "07";
string body = "A0000000031010";
string script = String.Format("{0}{1}{2}{3}{4}{5}", cla, ins, p1, p2,
lc, body);
byte[] buffer = new byte[ script.Length / 2];
//Console.WriteLine("buffer {0}", buffer);
for (int i = 0; i < script.Length; i = i + 2)
{
string temp = script.Substring(i, 2);
buffer[i / 2] = byte.Parse(temp,
System.Globalization.NumberStyles.HexNumber);
}
return buffer;
}
// ===================================== public void ScardTransmit() { SCARD_IO_REQUEST ioRecv = new SCARD_IO_REQUEST(); byte [] pbRecvBuffer = new byte [255]; int pcbRecvLength = 255; byte [] pbsendBuffer = this.GetSendBuffer();
int pbsendBufLen = pbsendBuffer.Length;
ioRecv.cbPciLength = ioRecv.ToString().Length;
IntPtr SCARD_PCI_T0 = GetPciT0();
uint uintret = SCardTransmit(pCardHandle, ref ioRecv, pbsendBuffer,
pbsendBufLen, SCARD_PCI_T0, pbRecvBuffer, ref pcbRecvLength);
}
答案 0 :(得分:0)
尝试发送以下内容:
0x00A4040000
至少应该归还一些东西。末尾的字节是可选的。 它们确实有用,但看看你是否可以从中获得一些东西。