Sending APDU commands to Write Data to a smartCard Reader using java smartcardio functions

1.7k views Asked by At

I am trying to write data to contactless card in HID Omnikey 5122 device using java smartcardIO functions.

The Data that I need to insert to the card is {00 01 02 03}.

APDU command I am trying to send through channel.transmit function is {FF D6 00 04 04 00 01 02 03} where:

  • FF is CLS
  • D6 is INS
  • 00 is P1
  • 04 is P2
  • 04 is Number of bytes to update
  • 00 01 02 03 is the data that I need to insert.

I am not able to correctly build the APDU command through below function. Can some one help me with this. I am using functions available in java smartcardio library.

ResponseAPDU respApdu = channel.transmit(           
                          new CommandAPDU(0xFF,0xD6,0x00,0x04,0x04,
                                          new byte[] {(byte) 0x00, 
                                          (byte) 0x01, 
                                          (byte)0x02,
                                          (byte)0x03}));

I am getting syntax error like constructor command is having invalid arguments.

1

There are 1 answers

2
ALe On

It looks like you are trying to send an UPDATE BINARY APDU to update the transparent file at offset 4 (this is what you provide in P1-P2). You have to use a CLA byte of 00h (if that file operation doesn't require the use of Secure Messaging). Since P1-P2 doesn't specify a short file identifier in your case, your currently selected file has

  • to be compatible with the READ/UPDATE BINARY commands
  • to have file size >=9 byres.