Categories: Code Examples | Java | NFC | WIMA2008
This page was last modified 16:43, 1 May 2008.
NFC Secure Element Example Java Card for Nokia6131
From Forum Nokia Wiki
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.
/** * 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()) { return; } // 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) value++; // return no error, in case everything was okay ISOException.throwIt(ISO7816.SW_NO_ERROR); break; // increase the value in the wallet case (byte) INS_DEC: if (value > 0x00) value--; // return no error, in case everything was okay ISOException.throwIt(ISO7816.SW_NO_ERROR); break; // 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.setOutgoing(); apdu.setOutgoingLength((byte) outBuffer.length); apdu.sendBytesLong(outBuffer, (short) 0, (byte) outBuffer.length); break; // all other INS default: // good practice: If you don't know the INStruction, say so: ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } } }
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Applet uploading using Jcop & ASK reader | jsautreau | Near Field Communication | 13 | 2008-04-15 11:34 |
| Exception with ISO14443Connection Connector.open and message "null" | smischi | Near Field Communication | 2 | 2008-01-21 16:31 |
| What are the operating modes of NFC devices? | Natalia Aramayo | Near Field Communication | 1 | 2008-04-30 09:38 |
| Secure element keysets | think_75 | Near Field Communication | 3 | 2007-09-27 17:08 |
| Store records in Internal secure card | super_beda | Near Field Communication | 2 | 2007-11-08 12:31 |
