Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 08:30, 23 July 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

NFC Secure Element Example Java Card for Nokia6131

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): Nokia 6131
Created: geri-m (01 May 2008)
Last edited: hamishwillee (23 Jul 2013)

Warning.pngWarning: This example was created for the NFC implementation provided on Series 40 devices, and may include use of features not yet available for NFC on Symbian devices.

This is the code for the JAR file in order to compile a real Java Card CAP File and put into the secure element of the Nokia 6131 (make sure you have either G&D SmartC@fe, SUN's JavaCard Developer Kit for JavaCard or JCOP Tools at hand). Download appropriate Eclipse/JCOP Project: File:Ticket

* Implementation of very simple wallet. The Wallet Container holds a
* value (byte) which can be increase, decreased and read by sending
* an appropriate APDU

package congress;
import javacard.framework.APDU;
import javacard.framework.ISO7816;
import javacard.framework.Applet;
import javacard.framework.ISOException;
* @author gmadlmay

public class Ticketing extends Applet {
* command set for communication between the
* J2ME application and Java Card Applet as well as
* the Java card Applet and the external reader

// Command (APDU INS) for increading the value in the wallet
private final static byte INS_INC = 0x01;
// Command (APDU INS) for decreading the value in the wallet
private final static byte INS_DEC = 0x02;
// command (APDU INS) for reading the value in the wallet
private final static byte INS_READ = 0x03;
// variable holding the amount stored in the wallet.
private byte value = (byte) 0x20;
public static void install(byte[] bArray, short bOffset, byte bLength) {
// GP-compliant JavaCard applet registration
new Ticketing()
.register(bArray, (short) (bOffset + 1), bArray[bOffset]);
public void process(APDU apdu) {
// Good practice: Return 9000 on SELECT
if (selectingApplet()) {
// grab the byte-array of the APDU
byte[] buf = apdu.getBuffer();
// check the INS Byte of the APDU and take
// the appropriate action
switch (buf[ISO7816.OFFSET_INS]) {
// increase the value in the wallet
case (byte) INS_INC:
if (value < 0xff)
// return no error, in case everything was okay
// increase the value in the wallet
case (byte) INS_DEC:
if (value > 0x00)
// return no error, in case everything was okay
// read the value of the wallet
case (byte) INS_READ:
// create a byte array out of the value (length: 1)
byte[] outBuffer = new byte[1];
outBuffer[0] = value;
// now send back the data.
apdu.setOutgoingLength((byte) outBuffer.length);
apdu.sendBytesLong(outBuffer, (short) 0, (byte) outBuffer.length);
// all other INS
// good practice: If you don't know the INStruction, say so:
This page was last modified on 23 July 2013, at 08:30.
50 page views in the last 30 days.