Java卡應用開發其實並不難(3)

鄒德強發表於2012-07-20

第一個Java卡程式的原始碼

 

以下是模板生成的程式原始碼:

 

package testpackage;

 

import ;

import ;

import ;

import ;

 

public class TESTCLASS extends Applet {

      public static void install(byte[] bArray, short bOffset, byte bLength) {

            // GP-compliant JavaCard applet registration

            new TESTCLASS()

                        .register(bArray, (short) (bOffset + 1), bArray[bOffset]);

      }

 

      public void process(APDU apdu) {

            // Good practice: Return 9000 on SELECT

            if (selectingApplet()) {

                  return;

            }

 

            byte[] buf = ();

            switch (buf[ISO7816.OFFSET_INS]) {

            case (byte) 0x00:

                  break;

            default:

                  // good practice: If you don't know the INStruction, say so:

                  ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);

            }

      }

}

當然,這僅僅是最簡單的一個起步,為了實現真正的應用,開發者需要在public void process(APDU apdu)方法中增加自己的處理,這樣就能夠按照使用者的需求開發不同的應用了。

相關文章