0

Am working on a project to read from and write data to SLE 4442 smart cards. The Card Reader am using is ACR38 from ACS. Following their APDU commands, I have being able to get access to the card and read some data. But am suspecting that I still have not being able to read the exact data inside. This is because, anytime my application is started, it brings out new data. I really don't know why is behaving that way, can somebody please spot where am getting wrong here? Below is my Java code:

CardChannel channel = card.getBasicChannel(); byte[] read_memory_card = {(byte) 0xFF, (byte) 0xB0, (byte) 0xA7A6A5A4, (byte) 0xA3A2A1A0, (byte) 0x00}; ResponseAPDU read_data_resp = channel.transmit(new CommandAPDU(read_memory_card)); if (read_data_resp.getSW1() == 0x90 && read_data_resp.getSW2() == 0x00) { System.out.println("Data in Card: " + read_data_resp.getData() + "and SW1: " + read_data_resp.getSW1()); }

What I get as a result:
Data in Card: [B@378bf509 and SW1: 144

Please note that Data in Card changes every time, the application is restarted.

Mr Heart
  • 142
  • 1
  • 10
  • 1
    why are you casting `0xA7A6A5A4` as a byte? this will only send the reader `0xA4`. Same goes with `0xA3A2A1A0`. Also you should output sw1 as hex, but you already know that sw1 is 0x90 becaues of your if statement. – Robert Snyder Feb 27 '16 at 23:33
  • @RobertSnyder, I saw the write-up exactly like that on their manual. I never knew it can be that easily compressed. Thanks for the correction – Mr Heart Feb 27 '16 at 23:39
  • Are you looking at section 4.6.2 for that? if so then you are doing it wrong. I'm not sure how to read what they are asking but they are referring to the bits. Therefor you asked for address(es) `1010 0100` and if i'm reading the document correcty `1000 000` has special meaning. – Robert Snyder Feb 27 '16 at 23:45
  • am actually looking at section 4.6.2, that's the one applicable to my type of smart card – Mr Heart Feb 27 '16 at 23:50
  • Possible duplicate of [Java: Syntax and meaning behind "\[B@1ef9157"? Binary/Address?](http://stackoverflow.com/questions/1040868/java-syntax-and-meaning-behind-b1ef9157-binary-address) – Michael Roland Mar 07 '16 at 19:29
  • @MrHeart did you manage to find a solution? I'm stuck too regarding the command to send for MSB and LSB – Apostolos Nov 19 '19 at 20:39
  • @Apostolos yeah I got it working both in Java and C#.NET – Mr Heart Dec 20 '19 at 12:55

1 Answers1

1

I'm assuming that you seeing "different" data isn't so much that it is truly different but rather you are printing out the pointer in memory that Java uses as a default toString(). I can only assume that read_data_resp.getData() retuurns a byte[] in which case you'll want to convert each value into a string if you want to visualize it. If you search google on how to convert a byte array to a hex string you'll find lots of answers.

Robert Snyder
  • 2,399
  • 4
  • 33
  • 65
  • 1
    I added this lines of code and it is not displaying anything: `byte[] data_read = read_data_resp.getData(); for (int i = 0; i < data_read.length; i++) { System.out.printf("%02X ", data_read[i]); }` – Mr Heart Feb 27 '16 at 23:47
  • 1
    @MrHeart Guessing by your information and the documentation that you are asking for a address to read from the card that is either invalid or contains no data. – Robert Snyder Feb 27 '16 at 23:50