《Java卡电子钱包实验报告(共25页).docx》由会员分享,可在线阅读,更多相关《Java卡电子钱包实验报告(共25页).docx(25页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上Java卡电子钱包实验报告需求分析可以应用于现实中的Java卡电子钱包需要有电子钱包的安装、选择与撤销选择、存款、借款、获取钱包余额以及身份验证。等功能。定义4条命令,分别为校验PIN、加钱、减钱和读余额。其中,加钱、减钱和读余额都是对钱包余额的操作.PIN的引入增加了钱包应用的安全性,Wallet应用要求在进行交易(加钱或减钱)之前,必须进行PIN校验,只有PIN校验成功后,才能对余额数据进行修改。同时在取消选择应用时,重载了 deselect方法将PIN的校验结果清空,从而要求在每次选择应用后都需进行PIN验证,避免了安全漏洞的产生。系统结构图安装public s
2、tatic void install(byte bArray,short bOffset,byte bLength)new Wallet(bArray,bOffset,bLength); 选择public boolean select()if (pin.getTriesRemaining()=0)return false;return true;撤销选择public void deselect()pin.reset();存款void debit(APDU apdu)/充值/这里/if(!pin.isValidated()ISOException.throwIt(SW_VERIFICATION_
3、REQUIRED);/short n,sum;byte buf = apdu.getBuffer(); short p2=(short)getUnsignedByte(bufISO7816.OFFSET_P2);n=(short)(bufISO7816.OFFSET_P1*256+p2);/取p1,p2转化为一个数.short强制转换sum=(short)(Balance+n);if(n0x00)if(sum=0x00)Balance=(short)(Balance + n);buf0=(byte)(Balance8);buf1=(byte)(Balance&0xff);apdu.setOut
4、goingAndSend(byte)0,(byte)2);elseISOException.throwIt(short)0x6102);else ISOException.throwIt(short)0x6101); 取款void credit(APDU apdu)/消费buf /这里/if(!pin.isValidated()ISOException.throwIt(SW_VERIFICATION_REQUIRED);/short m;byte buf = apdu.getBuffer(); short p2=(short)getUnsignedByte(bufISO7816.OFFSET_
5、P2);m=(short)(bufISO7816.OFFSET_P1*256+p2);/取1,p2转化为一个数.short强制转换if(m0)if(Balance m)Balance=(short)(Balance-m);buf0=(byte)(Balance8);buf1=(byte)(Balance&0xff);apdu.setOutgoingAndSend(byte)0,(byte)2);elseISOException.throwIt(short)0x6104); elseISOException.throwIt(short)0X6103);获取钱包余额public void getB
6、alance(APDU apdu)byte buf = apdu.getBuffer(); buf0=(byte)(Balance8);buf1=(byte)(Balance&0xff);apdu.setOutgoingAndSend(byte)0,(byte)2);身份验证private void verify(APDU apdu)byte buffer=apdu.getBuffer();byte byteRead =(byte)(apdu.setIncomingAndReceive();if(pin.check(buffer,ISO7816.OFFSET_CDATA,byteRead)=f
7、alse)ISOException.throwIt(SW_VERIFICATION_FAILED);Process方法public void process(APDU apdu)if ( selectingApplet()return; byte buf = apdu.getBuffer();switch(bufISO7816.OFFSET_INS) case (byte) DEBIT:debit(apdu);break;case (byte) CREDIT:credit(apdu);break;case (byte) GET_BALANCE:getBalance(apdu);break;/c
8、ase (byte) VERIFY:verify(apdu);break;/default:ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); APDU发送Name CLA INS P1P2 Lc Data Field Le (size of response) 返回选择 00a4.9000DEBIT 00 0x01 钱数 00 成功9000 失败6101 6102CREDIT 000x02 钱数 00 成功9000 失败6104 6103VERIFY 00 0x03 00 00 03 密码成功9000 未经验证进行其他操作0x6301密码错
9、误,或输入三次均错锁定6300GET_BALANCE 000x05 00 00 00 成功9000 失败6104 6103 测试数据1.cm /select |wallet1 = 00 A4 04 00 07 77 61 6C 6C 65 74 31 00 选择功能 ( nsec) send 00100 验证身份,输入正确密码 = 00 03 00 00 03 10 01 00 ( nsec) send 充值100 = 00 01 27 10 00 ( nsec) send 获取余额 = 00 05 00 00 00 ( nsec) /select |wallet2 撤销选择 = 00 A4
10、04 00 07 77 61 6C 6C 65 74 32 00 ( nsec) /select |wallet1 = 00 A4 04 00 07 77 61 6C 6C 65 74 31 00 选择 ( nsec) send 00101 = 00 03 00 00 03 10 01 01 密码错误第一次 (7044 usec) send 00101 = 00 03 00 00 03 10 01 01 密码错误第2次 ( nsec) send 00101 = 00 03 00 00 03 10 01 01 密码错误第3次 ( nsec) send 00100 = 00 03 00 00 03
11、 10 01 00 密码正确,但超三次了,无法再进入 ( nsec) /select |wallet1 = 00 A4 04 00 07 77 61 6C 6C 65 74 31 00 选择 ( nsec) send = 00 01 27 10 00 没有经过密码验证,无法进入充值 ( nsec) = 63 01 Status: 0x63014.充100花0元,不可以,6103花51,不可以,6103花50,剩50花50,剩0花1,不可以,6104充一元再冲100,101块再冲199,共300再冲1块,不可以,6102重置。冲301,不可以,6101冲0.不可以,6101关键代码安装publi
12、c static void install(byte bArray,short bOffset,byte bLength)new Wallet(bArray,bOffset,bLength); 选择public boolean select()if (pin.getTriesRemaining()=0)return false;return true;撤销选择public void deselect()pin.reset();存款void debit(APDU apdu)/充值/这里/if(!pin.isValidated()ISOException.throwIt(SW_VERIFICATI
13、ON_REQUIRED);/short n,sum;byte buf = apdu.getBuffer(); short p2=(short)getUnsignedByte(bufISO7816.OFFSET_P2);n=(short)(bufISO7816.OFFSET_P1*256+p2);/取p1,p2转化为一个数.short强制转换sum=(short)(Balance+n);if(n0x00)if(sum=0x00)Balance=(short)(Balance + n);buf0=(byte)(Balance8);buf1=(byte)(Balance&0xff);apdu.set
14、OutgoingAndSend(byte)0,(byte)2);elseISOException.throwIt(short)0x6102);else ISOException.throwIt(short)0x6101); 取款void credit(APDU apdu)/消费buf /这里/if(!pin.isValidated()ISOException.throwIt(SW_VERIFICATION_REQUIRED);/short m;byte buf = apdu.getBuffer(); short p2=(short)getUnsignedByte(bufISO7816.OFFS
15、ET_P2);m=(short)(bufISO7816.OFFSET_P1*256+p2);/取1,p2转化为一个数.short强制转换if(m0)if(Balance m)Balance=(short)(Balance-m);buf0=(byte)(Balance8);buf1=(byte)(Balance&0xff);apdu.setOutgoingAndSend(byte)0,(byte)2);elseISOException.throwIt(short)0x6104); elseISOException.throwIt(short)0X6103);获取钱包余额public void g
16、etBalance(APDU apdu)byte buf = apdu.getBuffer(); buf0=(byte)(Balance8);buf1=(byte)(Balance&0xff);apdu.setOutgoingAndSend(byte)0,(byte)2);身份验证private void verify(APDU apdu)byte buffer=apdu.getBuffer();byte byteRead =(byte)(apdu.setIncomingAndReceive();if(pin.check(buffer,ISO7816.OFFSET_CDATA,byteRead
17、)=false)ISOException.throwIt(SW_VERIFICATION_FAILED);Process方法public void process(APDU apdu)if ( selectingApplet()return; byte buf = apdu.getBuffer();switch(bufISO7816.OFFSET_INS) case (byte) DEBIT:debit(apdu);break;case (byte) CREDIT:credit(apdu);break;case (byte) GET_BALANCE:getBalance(apdu);break;/case (byte) VERIFY:verify(apdu);break;/default:ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 专心-专注-专业