-1

I'm trying to develop and Android application using host-based card emulation and am confused about the APDU message.

I've been trying to follow a few examples (2 at the bottom) but still don't know how to format my own APDU message. I'm developing both the HCE app and the reader app so i assume this needs to be done for both.

With and example of a retail store membership card, the membership number needing to be transferred across, how can the APDU messages be created?

http://www.slideshare.net/ChienMingChou/hce-tutorialv-v1 http://www.javaworld.com/article/2076450/client-side-java/how-to-write-a-java-card-applet--a-developer-s-guide.html?page=3

Waddas
  • 1,353
  • 2
  • 16
  • 28

2 Answers2

1

First of all APDU command/response pair - just Binary bytes blocks, no any magic except sometimes used cryptography.

To learn about APDU commands and responses please take a look into ISO 7816 specification:

  • Part 3: describes content and classes for APDU Commands and Responces
  • Part 4: (and few others) describes the basics Commands.

To learn deeper about the payment cards you should look into EMV specifications.

Can't say the specs mentioned here are simple for understanding, but if you feel strong to develop for cards, this specs better to know or keep it in your hands for clarifications and best practice.

Please also keep in mind that card manufacturers can implement own APDU commands as well as Java card applications. In this case you should look into specific card or card application manuals.

Your retail store cards may use standard APDUs from ISO or from card manufacture or implement own (javacard) commands. Without looking into your retail card specification or analyzing APDU traces it is not easy to say what commands really do.

iso8583.info support
  • 2,130
  • 14
  • 18
1

Just create a String with your APDU command, run it through a function to convert it into a byte array and return it. Nothing crazy.

Here are functions to go to/from String/byte[].

public static String byteArrayToHex(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) {
        sb.append(String.format("%02X", b));
    }
    return sb.toString();
}

public static byte[] hexToByteArray(String hexString) {
    int len = hexString.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
                | Character.digit(hexString.charAt(i + 1), 16));
    }
    return data;
}

As far as your exact use case of sending a member number, I'm not sure the format of that command, but if you have a format of what the String would look like, use the utility functions here to construct them.

Sam Edwards
  • 874
  • 8
  • 19