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

前端 未结 6 985
失恋的感觉
失恋的感觉 2020-12-13 22:15

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 a

6条回答
  •  不思量自难忘°
    2020-12-13 22:50

    here is some working example:

    CardChannel channel = card.getBasicChannel(); 
    
     byte[] selectMaestro={(byte)0x00, (byte)0xA4,(byte)0x04,(byte)0x00 ,(byte)0x07 ,(byte)0xA0 ,(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,(byte)0x04 ,(byte)0x30 ,(byte)0x60 ,(byte)0x00};
      byte[] getProcessingOptions={(byte)0x80,(byte)0xA8,(byte)0x00,(byte)0x00,(byte)0x02,(byte)0x83,(byte)0x00,(byte)0x00};
      byte[] readRecord={(byte)0x00,(byte)0xB2,(byte)0x02,(byte)0x0C,(byte)0x00};
    
      ResponseAPDU r=null;
    
       try {
         ATR atr = card.getATR(); //reset kartice
    
          CommandAPDU capdu=new CommandAPDU( selectMaestro   );
    
           r=card.getBasicChannel().transmit( capdu );
    
          capdu=new CommandAPDU(getProcessingOptions);
          r=card.getBasicChannel().transmit( capdu );
    
    
          capdu=new CommandAPDU(readRecord);
          r=card.getBasicChannel().transmit( capdu );
    

    This works with Maestro card, I can read PAN number, yet now I need to read MasterCard's PAN number. I do not know should I change the read record APDU or select application APDU. Anyone familiar with APDUs?

提交回复
热议问题