Skip to Main Content

Java Card

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Read Binary File, T=1

843851Dec 26 2008 — edited Jan 5 2009
Hello,

I'm trying to read a binary file from a card.

This is something I can easily do, at least until now :)

I'm testing a new card (with protocol T=1 instead of the T=0 I used so far) and I don't have the card technical document (with the APDUs format) but I guess the APDUs are the same (for the read binary command and other more general commands like the select and others alike).

I can select the pretended files and navigate in the card EFs/DFs, but for some reason I cant read a complete binary file (it stops before the last block reading).

This is the code I have used so far without problems:
private static byte[] readBinary() throws CardException, IOException {
  //CardChannel channel = getCardChannel();
  ByteArrayOutputStream os = new ByteArrayOutputStream(256);
  boolean finished = false;
  byte offset = (byte) 0x00;
  int i=1;
  while (!finished) {
	//Read binary command
	ResponseAPDU resp = channel.transmit(new CommandAPDU(0x00, 0xB0, offset,
			0x00, READ_BUFFER_LENGTH));
	i++;
	byte[] data = resp.getData();
	offset = (byte) (offset + (byte) 0x01);
	os.write(data);
	if (data.length < READ_BUFFER_LENGTH) {
		finished = true;
	}
  }
  return os.toByteArray();
}
Where READ_BUFFER_LENGTH = 256

If with the other cards I tested this code works fine why doesn't it work with this card? The only difference is at the transport protocol, this card protocol is T=1 and the other cards was T=0, but I thought that PC/SC would hide the transport protocol layer

Thanks for any help
Brian

Edited by: Brian.Rep on Dec 26, 2008 3:16 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 2 2009
Added on Dec 26 2008
3 comments
457 views