How do I read the PAN from an EMV SmartCard from Java

asabo picture asabo · Nov 12, 2008 · Viewed 25.9k times · Source

I need to read account number from Maestro/Mastercard with smart card reader. I am using Java 1.6 and its javax.smartcardio package. I need to send APDU command which will ask EMV application stored on card's chip for PAN number. Problem is, I cannot find regular byte array to construct APDU command which will return needed data anywhere...

Answer

Rasmus Faber picture Rasmus Faber · Nov 13, 2008

You shouldn't need to wrap the APDU further. The API layer should take care of that.

It looks like the 0x6D00 response just means that the application did not support the INS.

Just troubleshooting now, but you did start out by selecting the MasterCard application, right?

I.e. something like this:

void selectApplication(CardChannel channel) throws CardException {
  byte[] masterCardRid = new byte[]{0xA0, 0x00, 0x00, 0x00, 0x04};
  CommandAPDU command = new CommandAPDU(0x00, 0xA4, 0x04, 0x00, masterCardRid);
  ResponseAPDU response = channel.transmit(command);
  return response.getData();
}