posts - 93,  comments - 2,  trackbacks - 0
          1.new->Java Card Project
          2.new->Java Card Applet Class->AID Settings
          編寫卡內程序

          public class HelloApplet extends Applet {

           public static void install(byte[] bArray, short bOffset, byte bLength) {
            // GP-compliant JavaCard applet registration
            new HelloApplet().register(bArray, (short) (bOffset + 1),
              bArray[bOffset]);
           }

           public void process(APDU apdu) {
            // Good practice: Return 9000 on SELECT
            if (selectingApplet()) {
             return;
            }
            
            byte[] buf = apdu.getBuffer();
            short offset = ISO7816.OFFSET_CDATA;
            switch (buf[ISO7816.OFFSET_INS]) {
            case (byte) 0xE2:
             buf[offset++] = 0x01;
             buf[offset++] = 0x02;
             buf[offset++] = 0x03;
             buf[offset++] = 0x04;
             buf[offset++] = 0x05;
             buf[offset++] = 0x06;
             
             apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, (short)(offset-ISO7816.OFFSET_CDATA));
             break;
            case (byte) 0xE3:
             buf[offset++] = 0x11;
             buf[offset++] = 0x12;
             buf[offset++] = 0x13;
             buf[offset++] = 0x14;
             buf[offset++] = 0x15;
             buf[offset++] = 0x16; 
              
             apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA,(short) (offset-ISO7816.OFFSET_CDATA));
             break;
             default:
              ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
            }
           }

          }


          3.右鍵項目->Run Configurations...->Java Card Application右鍵選擇new->選擇新建的Applet->package Upload->aid

          4.新建卡外項目java project
          編寫卡內程序如下:

          public class TestHelloWorld {
           
           protected static RFCSMXIO smxio = null;
           @Before
           public void setUp() throws Exception {
            smxio = SMXIOFactory.createJDKSMXIO();
           }
           
           @Test
           public void test() {
            try {
             byte[] aid = ByteUtil.hexToByteArray("5200413120");
             RFCIOResult result = smxio.selectApplet(aid);
             int offset = 0;
             byte[] apdu = new byte[5];
             apdu[offset] = (byte)0x80;
             apdu[offset+1] = (byte)0xE2;
             apdu[offset+2] = 0;
             apdu[offset+3] = 0;
             apdu[offset+4] = 0;
             result = smxio.exchange(apdu);
             
             System.out.println("result: "+ByteUtil.byteArrayToHex(result.getResult()));
             boolean res = RFCSMXIOHelper.processCardIOResult(result);
             byte[] b = result.getResult();
             if(res){
              System.out.println(ByteUtil.byteArrayToHex(b));
             }
            } catch (Exception e) {
             e.printStackTrace();
            }
           }

          }

          6.安裝卡內程序
          jcop debug->upload package->install applet
          7.運行卡外程序
          posted on 2014-01-23 11:38 Terry Zou 閱讀(199) 評論(0)  編輯  收藏 所屬分類: JavaCard

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2014年1月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          Java

          搜索

          •  

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 门源| 南开区| 承德县| 新竹市| 曲阳县| 金溪县| 杂多县| 黄浦区| 鹤峰县| 九龙坡区| 鸡西市| 信阳市| 开远市| 镇坪县| 本溪| 双江| 贵港市| 汤原县| 武山县| 弥渡县| 卫辉市| 高平市| 苗栗县| 宁德市| 台北市| 临海市| 当雄县| 龙江县| 班玛县| 三河市| 南漳县| 共和县| 云霄县| 洞口县| 潞西市| 双柏县| 巴青县| 浪卡子县| 那曲县| 当雄县| 安多县|