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 閱讀(194) 評論(0)  編輯  收藏 所屬分類: JavaCard

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


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

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          Java

          搜索

          •  

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 奉化市| 阜平县| 资溪县| 仙游县| 牟定县| 阿坝县| 阆中市| 溧水县| 乐陵市| 平果县| 桐梓县| 隆化县| 阿尔山市| 宣城市| 莱芜市| 双城市| 高陵县| 盘锦市| 大同县| 香河县| 师宗县| 临清市| 海伦市| 西安市| 德江县| 高淳县| 隆林| 县级市| 新郑市| 容城县| 揭阳市| 峨边| 石棉县| 西华县| 东辽县| 嘉祥县| 柯坪县| 司法| 新民市| 梧州市| 潼南县|