bujji
bujji

Reputation: 11

How to read and store my name into smart card using java card? with example

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

Upvotes: 1

Views: 366

Answers (1)

MJay
MJay

Reputation: 1058

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

Upvotes: 0

Related Questions