This discussion is archived
7 Replies Latest reply: Oct 15, 2012 10:44 PM by Umer RSS

A way to send a String to the card

949970 Newbie
Currently Being Moderated
Hi,

I am a rookie in Javacard
I want to know how to send a string to the card .
I mean i have this


byte helloword = 0x00;
r = channel.transmit(new CommandAPDU((byte)0x80, HW_INS_SEND_STRING, helloword, (byte)0x00, (byte)10));

There is a way to put a string or an array byte to my var helloword; ??


because on my applet i have this method to recup the helloword

byte helloword[];
byte[] buffer = apdu.getBuffer();
apdu.setIncomingAndReceive();
               short length = (short)buffer[ISO7816.OFFSET_LC];
               Util.arrayCopyNonAtomic(buffer, (short)0, helloword, (short)0, (short) length);
  • 1. Re: A way to send a String to the card
    949970 Newbie
    Currently Being Moderated
    Help , i am sure that someone can answer o me .
    please !!!!!!!!!!!!!
  • 2. Re: A way to send a String to the card
    Umer Journeyer
    Currently Being Moderated
    Hi,

    Java card does not support string and char types. if you want to send string/chars for example 'Hello World' to the card and store them then you need to convert them into hex format and then send the converted hex string to the card.
    The command APDU will be then,
    CLA  --- Your class byte, can be 80 
    INS  --- Your Ins byte, can be 01
    P1   --- Parameter P1 can be 00
    P2   --- Parameter P2 can be 00
    LC   --- Length of Hello World hex string (0B)
    Data --- Hellow World Hex String (48656c6c6f20576f726c64)
    Le -- 00
  • 3. Re: A way to send a String to the card
    safarmer Expert
    Currently Being Moderated
    You could also use the following:
    CommandAPDU cmd = new CommandAPDU(cla, ins, p1, p2, "Hello, world!".getBytes("utf-8"), le);
    - Shane
  • 4. Re: A way to send a String to the card
    949970 Newbie
    Currently Being Moderated
    Thanks for your help it was verry useful
    i am a beginer and i didn t found a lot of document in javacard .
    I have two questions ?

    there is a way to create file on a javacard ? if yes how ?
    the second , my card was coming with a biometrical terminal , how can use that , just a simple code in the way to authentifiate and to compare my fingerprint ?

    thanks
  • 5. Re: A way to send a String to the card
    965389 Newbie
    Currently Being Moderated
    yes you can create file on your java card,

    what is the type of your card?

    you can use class byte 80 with instruction E0 to create file

    | E0 | ISO 7816-9 6.1 | CREATE FILE |
    | 80 E0 02 00 0C Manual | GEMPLUS MPCOS-EMV | CREATE FILE |
    | 80 E0 xx xx xx FCI length | 3GPP TS 11.11 | CREATE FILE |
    | 80 E0 xx xx xx FCI length | SAGEM SCT U34 | CREATE FILE
  • 6. Re: A way to send a String to the card
    Sebastien_Lorquet Journeyer
    Currently Being Moderated
    this response is misleading

    because an APDU is described in a spec does not mean all cards will support it. Above ISO7816-3, about everyting in the ISO7816 specs is optional.

    to create files in a javacard you need a file system applet first.

    there are no generic javacard APIs to support that, you have to create everything by yourself from command dispatcher to file storage.

    if you're working with a SIM card then maybe you can rely on the SIM API. Sorry, I don't know anything in this domain.

    regards
  • 7. Re: A way to send a String to the card
    Umer Journeyer
    Currently Being Moderated
    Yes Sebastien is right. Only GSM cards support file system. Otherwise you need to create your own applet to do so and there are sample examples already discussed in the previous threads.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points