1

could some one tell me how to read and store my name in smart card using java card? i am using JCIDE 5.0

i want to know how to write program for read and store my name in javacard. Please help me out i am new to java card development

bujji
  • 11
  • 2

1 Answers1

0

You can write a specific applet in which you can store your name in a non-volatile memory.

Non-volatile memories are defined in your main class (which extend Applet) and initialized in your constructor. Methods for set and get your name should be implemented inside the process method.

As you select this applet, you are able to call the get method, whether you are in contact or contactless interfaces.


Appendix 1:

package pkgName;

import javacard.framework.APDU;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;

public class appName extends javacard.framework.Applet implements ExtendedLength {

private static final byte[] nameArr;

private appName(byte[] bArray, short bOffset, byte bLength) {
    nameArr[] = new byte[128];
    register();
} // end of constructor

public static void install(byte[] bArray, short bOffset, byte bLength) {
    appName name = new appName(bArray, bOffset, bLength);
}

public boolean select() {}

public void deselect() {}

public void process(APDU apdu) {
    switch (ins) {
        case (byte) 0x01:
            set_name(apdu);
            break;
        case (byte) 0x02:
            get_name(apdu);
        default:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }
} // end of process method

private static void set_name(APDU apdu) {
    byte[] buffer = apdu.getBuffer();
    short len = apdu.setIncomingAndReceive();
    Util.arrayCopy(buffer, (short) ISO7816.OFFSET_CDATA, nameArr, (short) 0, len);
    return;
}

private static void get_name(APDU apdu) {
    byte[] buffer = apdu.getBuffer();
    short len = apdu.setIncomingAndReceive();
    Util.arrayCopy(nameArr, (short) 0, buffer, (short) 0, len);
    apdu.setOutgoingAndSend((short) 0, len);
    return;
}

} // end of class JAVA_APPLET
MJay
  • 987
  • 1
  • 13
  • 36
  • Could you write code for the above mentioned – bujji Jul 03 '23 at 09:29
  • @kusumabujji asking for code is against the rules, but you can see wallet example of oracle available in JCDK. – MJay Jul 03 '23 at 09:36
  • @kusumabujji this link can help: https://www.oracle.com/java/technologies/java-archive-downloads-javame-downloads.html#javacarddevkitv212 – MJay Jul 03 '23 at 09:41
  • If you download java card kit 2.2.1, in contains samples. there are examples were balance value is stored in non-volatile memory. You could instead store your name in a non-volatile byte array. – MJay Jul 03 '23 at 09:43
  • Tqs for the suggestion i tried to implement an applet but i couldn't that why i have asked – bujji Jul 03 '23 at 09:47
  • @bujji please check my answer again (Appendix 1) – MJay Jul 15 '23 at 08:19