I am using an ACS AET65 card reader trying to save a string on a smart card and then read it. I am using the Iphone API of the smart card and I can get the terminal and connect to the card. However, I read the ISO 7816 specification and I really got lost.
All I have to do is write a 3K line to the card and then read it back. It. From what I explored, it seems that applets should be installed on these cards, but I'm sure there should be a way to just write a simple byte array and return it.
I do not know ho to create APDU commands for this. I tried READING BINARS, WRITE BINARS, MAKE SURE BINARS, but of course, I am doing something wrong. It always returns 0x6E and 0x00 as bytes of the response SW1 and SW2, which means an error. Here is a snippet of the part where I send test commands to the applet with a small line:
Card card = cardTerminal.connect("*"); card.beginExclusive(); System.out.println("Card protocol: "+card.getProtocol()); CardChannel channel = card.getBasicChannel(); String jsonStr = "small test string"; byte[] totalData = new byte[256]; byte[] data = jsonStr.getBytes(); System.arraycopy(data, 0, totalData, 0, data.length); CommandAPDU eraseCommand = new CommandAPDU(0x00, 0x0E, 0x00, 0x00, data, 0x00); ResponseAPDU eraseCommandResponse = channel.transmit(eraseCommand); int eSw1 = eraseCommandResponse.getSW1(); int eSw2 = eraseCommandResponse.getSW2(); // returns 6E00, error System.out.println("Erase Response SW1: " + toHexString(eSw1) + " and SW2: " + toHexString(eSw2)); CommandAPDU writeCommand = new CommandAPDU(0x00, 0xD0, 0x00, 0x00, data, 0x00); ResponseAPDU commandResponse = channel.transmit(writeCommand); int sw1 = commandResponse.getSW1(); int sw2 = commandResponse.getSW2(); // returns 6E00, error System.out.println("Write Response SW1: " + toHexString(sw1) + " and SW2: " + toHexString(sw2)); byte[] totalReadData = new byte[255]; CommandAPDU readCommand = new CommandAPDU(0x00, 0xB0, 0x00, 0x00, totalReadData, 0); ResponseAPDU readCommandResponse = channel.transmit(readCommand); int rSw1 = readCommandResponse.getSW1(); int rSw2 = readCommandResponse.getSW2(); // returns 6E00, error System.out.println("Read Response SW1: " + toHexString(rSw1) + " and SW2: " + toHexString(rSw2)); byte[] totalReadData2 = readCommandResponse.getData(); // always returns an empty array System.out.println("Total data read: "+totalReadData2.length); card.endExclusive();
How can I accomplish this using the smart card API?
Thanks! Eduardo