下载 >  开发技术 >  其它 > javacard applet 开发实例 正常运行 带jar包

javacard applet 开发实例 正常运行 带jar包 评分:

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[] mifarePass9={(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<AmbiqConstant.LEN_MIFARE_PASS; i++) { buf[i]=mifarePass8[i]; } for(i=0;i<AmbiqConstant.BYTES_PER_BLOCK;i++) { buf[AmbiqConstant.LEN_MIFARE_PASS+i]=send[0*AmbiqConstant.BYTES_PER_BLOCK+i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_WRITE, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_8+AmbiqConstant.BLOCK_NUM_OF_0)); if(i==0) { //apdu.setOutgoingAndSend((short)8, (short) 4); //javacard.framework.Util.arrayCopy(send, (short)8, apdu.getBuffer(), (short)0, (short)16); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S8); } for(i=0;i<AmbiqConstant.BYTES_PER_BLOCK;i++) { buf[AmbiqConstant.LEN_MIFARE_PASS+i]=send[1*AmbiqConstant.BYTES_PER_BLOCK+i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_WRITE, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_8+AmbiqConstant.BLOCK_NUM_OF_1)); if(i!=0) { ISOException.throwIt(AmbiqConstant.SW_WRONG_S8); } for(i=0;i<AmbiqConstant.BYTES_PER_BLOCK;i++) { buf[AmbiqConstant.LEN_MIFARE_PASS+i]=send[2*AmbiqConstant.BYTES_PER_BLOCK+i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_WRITE, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_8+AmbiqConstant.BLOCK_NUM_OF_2)); if(i!=0) { ISOException.throwIt(AmbiqConstant.SW_WRONG_S8); } for(i=0; i<AmbiqConstant.LEN_MIFARE_PASS; i++) { buf[i]=mifarePass9[i]; } for(i=0;i<4;i++) { buf[AmbiqConstant.LEN_MIFARE_PASS+i]=send[3*AmbiqConstant.BYTES_PER_BLOCK+i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_WRITE, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_9+AmbiqConstant.BLOCK_NUM_OF_0)); if(i!=0) { ISOException.throwIt(AmbiqConstant.SW_WRONG_S9); } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_WRITE, buf, (short)0, (short)(AmbiqConstant.BLOCKS_PER_SECTOR*AmbiqConstant.SECTOR_NUM_OF_9+AmbiqConstant.BLOCK_NUM_OF_1)); if(i==0) { apdu.setOutgoingAndSend((short)0, (short) 0); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S9); } } else { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); } break; case AmbiqConstant.INS_GET_CSN: if(buf[ISO7816.OFFSET_P1]!=0 || buf[ISO7816.OFFSET_P2]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); return; } else if(buf[ISO7816.OFFSET_LC]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); return; } for(i=0; i<AmbiqConstant.LEN_MIFARE_PASS; i++) { buf[i]=mifarePass8[i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_READ, buf, (short)0, (short)0); if(i==0) { //apdu.setOutgoingAndSend((short)AmbiqConstant.LEN_MIFARE_PASS, (short) 4); apdu.setOutgoingAndSend((short)0, (short)4); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_B0); } break; case AmbiqConstant.INS_SET_PASS: if(buf[ISO7816.OFFSET_P1]==0 && buf[ISO7816.OFFSET_P2]==0 && buf[ISO7816.OFFSET_LC]==0x20)//set admin password { if(Util.arrayCompare(adminPass, (short)0, buf, ISO7816.OFFSET_CDATA, AmbiqConstant.LEN_ADMIN_PASS)==0) { Util.arrayCopy(buf, (short)(ISO7816.OFFSET_CDATA+AmbiqConstant.LEN_ADMIN_PASS), adminPass, (short)0, AmbiqConstant.LEN_ADMIN_PASS); apdu.setOutgoingAndSend((short)0, (short) 0); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_ADMIN); } } else if(buf[ISO7816.OFFSET_P1]==0x01 && buf[ISO7816.OFFSET_P2]==0 && buf[ISO7816.OFFSET_LC]==0x18) //set mifare password for sector 8 { if(Util.arrayCompare(adminPass, (short)0, buf, ISO7816.OFFSET_CDATA, AmbiqConstant.LEN_ADMIN_PASS)==0) { for(i=0;i<AmbiqConstant.LEN_MIFARE_PASS;i++) mifarePass8[i]=buf[ISO7816.OFFSET_CDATA+AmbiqConstant.LEN_ADMIN_PASS+i]; apdu.setOutgoingAndSend((short)0, (short) 0); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_ADMIN); } } else if(buf[ISO7816.OFFSET_P1]==0x02 && buf[ISO7816.OFFSET_P2]==0 && buf[ISO7816.OFFSET_LC]==0x18) //set mifare password for sector 9 { if(Util.arrayCompare(adminPass, (short)0, buf, ISO7816.OFFSET_CDATA, AmbiqConstant.LEN_ADMIN_PASS)==0) { for(i=0;i<AmbiqConstant.LEN_MIFARE_PASS;i++) mifarePass9[i]=buf[ISO7816.OFFSET_CDATA+AmbiqConstant.LEN_ADMIN_PASS+i]; apdu.setOutgoingAndSend((short)0, (short) 0); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_ADMIN); } } else { ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } break; case AmbiqConstant.INS_SET_OTHER_PASS: /*Set Mifare password for some sector except 8,9 * Returns the content of the block; total 16bytes. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x53 Set Mifare password for other sector except 8,9 P1 1 0x00 P2 1 0x00 Lc field 1 0x18 Length Lc Data[0-15] 16 ATS Admin password Lc Data[16-23] 8 MFare password Output parameters: SW */ if(buf[ISO7816.OFFSET_P1]==0x00 && buf[ISO7816.OFFSET_P2]==0 && buf[ISO7816.OFFSET_LC]==0x18) //set mifare password for sector 8 { if(Util.arrayCompare(adminPass, (short)0, buf, ISO7816.OFFSET_CDATA, AmbiqConstant.LEN_ADMIN_PASS)==0) { for(i=0;i<AmbiqConstant.LEN_MIFARE_PASS;i++) mifarePassDefault[i]=buf[ISO7816.OFFSET_CDATA+AmbiqConstant.LEN_ADMIN_PASS+i]; apdu.setOutgoingAndSend((short)0, (short) 0); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_ADMIN); } } else { ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } break; case AmbiqConstant.INS_GET_BLOCK: /*Get Mifare block data * Returns the content of the block; total 16bytes. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x50 Get Mifare block data P1 1 Sector number P2 1 Block number Lc field 1 0x10 Admin pass length Lc Data[0-15] 16 ATS Admin password Output parameters: SW+16 bytes data; */ if(buf[ISO7816.OFFSET_LC]==0x10)//Get Entire Mifare Ticket data { short blockNumber=(short)(AmbiqConstant.BLOCKS_PER_SECTOR*buf[ISO7816.OFFSET_P1]+buf[ISO7816.OFFSET_P2]); 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]=mifarePassDefault[i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_READ, buf, (short)0, blockNumber); if(i==0) { apdu.setOutgoingAndSend((short)8, (short)16); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S9); } } else { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); } break; case AmbiqConstant.INS_SET_BLOCK: /*set Mifare block data * Returns SW. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x51 set Mifare block data P1 1 Sector number P2 1 Block number Lc field 1 0x20 Length Lc Data[0-15] 16 ATS Admin password Lc Data[16-31] 16 Data in block Output parameters: SW; */ if(buf[ISO7816.OFFSET_LC]==0x20)//Set Block data { short blockNumber=(short)(AmbiqConstant.BLOCKS_PER_SECTOR*buf[ISO7816.OFFSET_P1]+buf[ISO7816.OFFSET_P2]); 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]=mifarePassDefault[i]; } i= JZSystem.readWriteMifare(JZSystem.MIFARE_PASSWORD_WRITE, buf, (short)0, blockNumber); if(i==0) { apdu.setOutgoingAndSend((short)0, (short)0); } else { ISOException.throwIt(AmbiqConstant.SW_WRONG_S9); } } else { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); } break; case AmbiqConstant.INS_GET_APPLET_VER: /*Get applet version * Returns the version number of applet, one byte. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x55 Get applet version P1 1 0x00 P2 1 0x00 Lc field 1 0x00 Length Output parameters: 1byte+SW */ if(buf[ISO7816.OFFSET_P1]!=0 || buf[ISO7816.OFFSET_P2]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); return; } else if(buf[ISO7816.OFFSET_LC]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); return; } buf[0]=AmbiqConstant.APPLET_VERSION; apdu.setOutgoingAndSend((short)0, (short)1); break; default: // good practice: If you don't know the INStruction, say so: ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } } } }
...展开详情收缩
2014-05-30 上传大小:50KB
分享
收藏 (3) 举报

评论 共5条

shichengjiang 请问怎么运行
2017-08-17
回复
dai148 在学习阶段,想找个例子,下来看看
2016-11-24
回复
u010723879 对我来说并没有很大帮助
2015-11-16
回复
qq_14887587 很有用的javacard
2015-10-04
回复
hui61001 刚下载下来,还没试,也只是在学习阶段,想找个例子
2015-08-12
回复
JAVA智能卡原理与应用开发

javacard开发资料,javacard applet开发适用

立即下载
JavaCard helloworld applet

目前常见的智能IC卡运行着JavaCard虚拟机,智能IC卡上可以运行由精简后的Java语言编写的卡应用(简称Applet)。智能IC卡的Applet不能自己启动,必须由外部终端(例如POS机,地铁刷卡终端等)向卡片发送Select命令,由此选中卡片的Applet,Applet才能运行。Appplet侧重于数据的处理,没有花销的I/O功能。

立即下载
JavaCard Cos 系统原理文档资料

压缩包里面有8份关于智能卡系统,也就是JavaCard Cos的文档资料,pdf和ppt的形式。有JavaCard API的,JavaCard Cos原理讲解的,有JavaCard Applet开发的等等。

立即下载
Java智能卡开发关键技术与实例.pdf

Javacard 智能卡讲解,pdf 版本。包括,智能卡知识,Javacard开发实例,7816协议,apdu讲解。

立即下载
javaCard开发环境配置

javaCard开发环境配置 利用eclipse进行javacard的开发

立即下载
Developing secure Java Card applications

深入浅出地描述了Javacard的加密应用的开发过程,适合有Java语言基础的快速开发JavaCard Applet,给出了每个步骤代码示例

立即下载
javacard开发环境 Eclipse 配置完成

javacard开发环境 Eclipse 配置完成 安装了jdk后可以直接开发

立即下载
JavaCard入门源码

Hello JavaCard源码,非常简单JavaCard入门工程

立即下载
JAVA卡相关规范

包含了JAVACARD开发中用到的EMV规范、GP规范以及JAVACARD的基本原理。

立即下载
javacard jcop 配置完成的Eclipse 开发java卡

配置完成的Eclipse环境,可以开发java卡,javacard jcop nxp 环境配置完成,测试可运行

立即下载
Java Card v2.2.1 API

关于Java Card v2.2.1 API制作的chm文档

立即下载
java card development kit

java_card_kit-2_2_2-windows.zip 应用于javacard开发

立即下载
JAVA CARD 3.0.4 规范

JAVA CARD 3.0.4 规范,JAVA CARD 开发用得到的

立即下载
JavaCard API

JavaCard API

立即下载
JavaCard应用程序开发

JavaCard应用程序开发

立即下载
JCOP Eclipse javacard 插件

JCOP Eclipse javacard 插件

立即下载
java卡外部认证指令运算

根据GP规范,计算java卡的外部认证指令,另外,里面用到的“PBOC_3DES_MAC” 可直接在我的资源下找到。

立即下载
eclipse javacard 开发插件

jcde是基于sun的javacard开发环境jcdk命令行开发的eclipse集成插件。可以用于快速构建javacard工程,以及编译和调试。

立即下载
javacard开发3.04

最新javacard开发包,从oracle下载的。

立即下载
Java卡API_V2.2.1

《Java卡API_V2.2.1 中文版 》本文档是Java卡2.2.1 应用程序接口(API)规范

立即下载

热点文章

下载码下载
做任务获取下载码
取消 提交下载码
img

spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip

资源所需积分/C币 当前拥有积分 当前拥有C币
5 0 0
点击完成任务获取下载码
输入下载码
为了良好体验,不建议使用迅雷下载
img

javacard applet 开发实例 正常运行 带jar包

会员到期时间: 剩余下载个数: 剩余C币: 剩余积分:0
为了良好体验,不建议使用迅雷下载
VIP下载
您今日下载次数已达上限(为了良好下载体验及使用,每位用户24小时之内最多可下载20个资源)

积分不足!

资源所需积分/C币 当前拥有积分
您可以选择
开通VIP
4000万
程序员的必选
600万
绿色安全资源
现在开通
立省522元
或者
购买C币兑换积分 C币抽奖
img

资源所需积分/C币 当前拥有积分 当前拥有C币
5 4 45
为了良好体验,不建议使用迅雷下载
确认下载
img

资源所需积分/C币 当前拥有积分 当前拥有C币
5 0 0
为了良好体验,不建议使用迅雷下载
VIP和C币套餐优惠
img

资源所需积分/C币 当前拥有积分 当前拥有C币
5 4 45
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
确认下载
下载
您还未下载过该资源
无法举报自己的资源

兑换成功

你当前的下载分为234开始下载资源
你还不是VIP会员
开通VIP会员权限,免积分下载
立即开通

你下载资源过于频繁,请输入验证码

您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:webmaster@csdn.net!

举报

  • 举报人:
  • 被举报人:
  • *类型:
    • *投诉人姓名:
    • *投诉人联系方式:
    • *版权证明:
  • *详细原因: