我正在尝试向智能卡发送命令。我用一个金雅拓 IDBridge CT30(PC TWIN 读卡器) http://www.smartcardfocus.com/images/content/GEMTR.jpg and a ID桥K30 http://cartesapuce-discount.com/76-371-thickbox/lecteur-de-cartes-a-puce-usb-gempc-tr.jpg通过 USB 连接到 Android 设备。
我尝试通过 USB 发送 SELECT APDU 命令:
boolean claim = openedConnection.claimInterface(usbInterface, true);
byte[] data = new byte[]{
(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x0C,
(byte) 0x07, (byte) 0xA0, (byte) 0x00, (byte) 0x00,
(byte) 0x01, (byte) 0x18, (byte) 0x45, (byte) 0x4E};
之后我收到了答复:
final int dataTransferred = this.openedConnection.bulkTransfer(endPointOut, data, data.length, TIMEOUT_MS);
if(!(dataTransferred == 0 || dataTransferred == data.length)) {
throw new Exception("Error durring sending command [" + dataTransferred + " ; " + data.length + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
final byte[] responseBuffer = new byte[endPointIn.getMaxPacketSize()];
final int dataTransferred = this.openedConnection.bulkTransfer(this.endPointIn, responseBuffer, responseBuffer.length, TIMEOUT_MS);
Console.writeLine("USB Retrieve: " + dataTransferred + " " + responseBuffer.length);
if(dataTransferred >= 0){
return responseBuffer;
}
throw new Exception("Error durring receinving response [" + dataTransferred + "]");
那个答案是
0x00 0x00 0x00 0x00 0x00 0xA0 0x00 0x41 0x03 0x00
但是,我应该得到一个答案0x90 0x00
根据测试项目在这里 http://labs.a-trust.at/developer/ShowSource.aspx?id=114.
我究竟做错了什么?有谁能够帮助我?我使用正确的方法吗?我没有使用默认的包类javax.smartcardio
。我使用 USB 接口类(例如USB设备 https://developer.android.com/reference/android/hardware/usb/UsbDevice.html) 直接地。