I would like to read a specific block on Mifare classic using Java's javax.smartcardio. Here's my code:
public byte[] getCardUID() throws CardException {
CardTerminals terminals = TerminalFactory.getDefault().terminals();
terminal = terminals.list().get(0);
Card card = terminal.connect("*");
CardChannel channel = card.getBasicChannel();
CommandAPDU command = new CommandAPDU( new byte[] { (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0xD4, (byte) 0x4A, (byte) 0x01, (byte) 0x00 });
ResponseAPDU response = channel.transmit(command);
card.disconnect(true);
if (response.getSW1() == 0x90) {
byte[] data = response.getData();
data = Arrays.copyOfRange(data, 0x08, data.length);
return data;
}
return new byte[] {};
}
This method (sample found on internet) successfully reads the UID of the card, but when I try to construct my own command, I always become error SW1=63.
On this site (http://www.acs.com.hk/drivers/eng/API_ACR122U_v2.00.pdf) i have found some informations about APDU, but nothing is working and i cannot find out why. I have tried following command without success (always error 63): FF B0 00 04 10 (B0 - read binary block, 04 - number of sector, 10 - read 16 bytes). I have also tried reading only one byte, reading value block (INS B1) but also no success.
FF 00 00 00 ... (from my example) should be a direct transmit, but i don't know following instructions for reading a block.
Can anyone help me? Thanks a lot. (Sorry for my english)
javax.smartcardio
. Maybe the traffic is going to the internal SAM smart card instead of to the mifare card? If you open your reader, does it contain a contact smart card? – martijno