0

i created a file in a smart card using this apdu command :

String apdu = "90CD00000700000E0EA0000000"; channel.transmit(new CommandAPDU(DatatypeConverter.parseHexBinary(apdu)));

the file is successefuly created , however i can't write data in that file , i tried this command : String apdu = "903D00003B00000000000034" + data + "00";

but it failed with a response : sw1 91 sw2 BE (Out of boundary)

what is the problem about this file ?

leonidas79
  • 437
  • 2
  • 7
  • 19

1 Answers1

1

DESFire commands use little-endian byte order.

Your length (000034) gets interpreted as 3407872 bytes. You need to use 340000 to encode 52.

Try a shorter write, e.g.: 903D00000F00000000080000112233445566778800 to write '1122334455667788'...

Good luck!

EDIT>

Adjust lengths in P3 of APDU and WriteData for longer writes, e.g.:

  • 903D0000170000000010000000112233445566778899AABBCCDDEEFF00

Note that DESFire has a frame size limit which limits the number of bytes that can be written in a single command exchange (for ISO wrapped DESFire WriteData command it is approximately 47 bytes of data). You need to perform several writes with offset (remember litte-endian encoding) or use ADDITIONAL FRAME mechanism -- see your DESFire manual (the latter is slightly faster).

vlp
  • 7,811
  • 2
  • 23
  • 51
  • thx for your answer , it's working well for this shorter write , but if i try a longer one i always get 8 caracters (8 bytes) , what if i want write long data with for exemple 52 ? – leonidas79 Jun 05 '19 at 21:36