您好,欢迎光临本网站![请登录][注册会员]  
文件名称: javacard applet 开发实例 正常运行 带jar包
  所属分类: 其它
  开发工具:
  文件大小: 50kb
  下载次数: 0
  上传时间: 2014-05-30
  提 供 者: wyx***
 详细说明: javacard applet 开发实例 正常运行 带jar包 package mifare; import com.ibm.jz.JZSystem; import javacard.framework.APDU; import javacard.framework.Applet; import javacard.framework.ISO7816; import javacard.framework.ISOException; import javacard.framework.Util; public class AmbiqApplet extends Applet { byte[] mifarePassDefault={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] mifarePass8={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] m ifarePass9={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] adminPass={(byte)0x40,(byte)0x41,(byte)0x42,(byte)0x43,(byte)0x44,(byte)0x45,(byte)0x46,(byte)0x47,(byte)0x48,(byte)0x49,(byte)0x4a,(byte)0x4b,(byte)0x4c,(byte)0x4d,(byte)0x4e,(byte)0x4f}; public static void install(byte[] bArray, short bOffset, byte bLength) { // GP-compliant JavaCard applet registration new AmbiqApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]); } public void process(APDU apdu) { short i; byte[] send=new byte[52]; byte[] send2=new byte[24]; // Good practice: Return 9000 on SELECT if (selectingApplet()) { return; } byte[] buf = apdu.getBuffer(); if(buf[ISO7816.OFFSET_CLA]==AmbiqConstant.CLS_AMBIQ) { switch (buf[ISO7816.OFFSET_INS]) { case AmbiqConstant.INS_GET_MIFARE: if(buf[ISO7816.OFFSET_P1]!=0 || buf[ISO7816.OFFSET_P2]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); return; } /*Get Entire Mifare Ticket data * Returns back the content of the entire sector 8 (3 block 8.0, 8.1, 8.2) and the first 4 bytes of block 9.0; total 52bytes. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x20 Read entire data P1 1 0x00 Sector number P2 1 0x00 Lc field 1 0x10 Admin pass length Lc Data[0-15] 16 ATS Admin password Output parameters: 52 bytes; 48bytes of sector 8 and the value of the electronic purse (4bytes) stored in sector 9. */ else if(buf[ISO7816.OFFSET_LC]==0x10)//Get Entire Mifare Ticket data { if(Util.arrayCompare(adminPass, (short)0, buf, ISO7816.OFFSET_CDATA, (short)16)!=0) { ISOException.throwIt(AmbiqConstant.SW_WRONG_ADMIN); } for(i=0; i<8; i++) { buf[i]=mifarePass8[i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_READ, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_8+AmbiqConstant.BLOCK_NUM_OF_0)); if(i==0) { //javacard.framework.Util.arrayCopy(send, (short)8, apdu.getBuffer(), (short)0, (short)16); javacard.framework.Util.arrayCopy(buf, (short)8, send, (short)0, AmbiqConstant.BYTES_PER_BLOCK); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S8); } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_READ, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_8+AmbiqConstant.BLOCK_NUM_OF_1)); if(i==0) { //javacard.framework.Util.arrayCopy(send, (short)8, apdu.getBuffer(), (short)16, (short)16); javacard.framework.Util.arrayCopy(buf, (short)8, send, (short)16, AmbiqConstant.BYTES_PER_BLOCK); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S8); } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_READ, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_8+AmbiqConstant.BLOCK_NUM_OF_2)); if(i==0) { //javacard.framework.Util.arrayCopy(send, (short)8, apdu.getBuffer(), (short)32, (short)16); javacard.framework.Util.arrayCopy(buf, (short)8, send, (short)32, AmbiqConstant.BYTES_PER_BLOCK); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S8); } for(i=0; i<8; i++) { buf[i]=mifarePass9[i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_READ, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_9+AmbiqConstant.BLOCK_NUM_OF_0)); if(i==0) { javacard.framework.Util.arrayCopy(buf, (short)8, send, (short)48, (short)4); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S9); } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_READ, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_9+AmbiqConstant.BLOCK_NUM_OF_1)); if(i==0) { if(javacard.framework.Util.arrayCompare(buf, (short)8, send, (short)48, (short)4)!=0) { ISOException.throwIt(AmbiqConstant.SW_CARD_COR); } javacard.framework.Util.arrayCopy(send, (short)0, buf, (short)0, (short)52); apdu.setOutgoingAndSend((short)0, (short) 52); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S9); } } else { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); } break; case AmbiqConstant.INS_SET_MIFARE: if(buf[ISO7816.OFFSET_P1]!=0 || buf[ISO7816.OFFSET_P2]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); } /*Set Entire Mifare Ticket data Sets the content of the entire sector 8 (3 block 8.0, 8.1, 8.2) and the first 4 bytes of block 9.0; total 52bytes. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x20 Write entire data P1 1 0x00 Sector number P2 1 0x00 Lc field 1 0x44(16+52) Admin pass length + 52data bytes Lc Data[0-15] 16 ATS Admin password Lc Data[16-43] 52 Ticket data Output parameters: None. Return Value: 0x90,00 on success.*/ else if(buf[ISO7816.OFFSET_LC]==0x44)//Set Entire Mifare Ticket data { if(Util.arrayCompare(adminPass, (short)0, buf, ISO7816.OFFSET_CDATA, (short)16)!=0) { ISOException.throwIt(AmbiqConstant.SW_WRONG_ADMIN); } javacard.framework.Util.arrayCopy(buf, (short)21, send, (short)0, (short)52); for(i=0; i
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: javacard applet 开发实例
 输入关键字,在本站1000多万海量源码库中尽情搜索: