您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > Java卡电子钱包实验报告
Java卡电子钱包实验报告需求分析可以应用于现实中的Java卡电子钱包需要有电子钱包的安装、选择与撤销选择、存款、借款、获取钱包余额以及身份验证。等功能。定义4条命令,分别为校验PIN、加钱、减钱和读余额。其中,加钱、减钱和读余额都是对钱包余额的操作.PIN的引入增加了钱包应用的安全性,Wallet应用要求在进行交易(加钱或减钱)之前,必须进行PIN校验,只有PIN校验成功后,才能对余额数据进行修改。同时在取消选择应用时,重载了deselect方法将PIN的校验结果清空,从而要求在每次选择应用后都需进行PIN验证,避免了安全漏洞的产生。系统结构图安装publicstaticvoidinstall(byte[]bArray,shortbOffset,bytebLength){newWallet(bArray,bOffset,bLength);}选择publicbooleanselect(){if(pin.getTriesRemaining()==0)returnfalse;returntrue;}撤销选择publicvoiddeselect(){pin.reset();}存款voiddebit(APDUapdu)//充值{//////////这里//////////////if(!pin.isValidated())ISOException.throwIt(SW_VERIFICATION_REQUIRED);//////////////////////////////shortn,sum;byte[]buf=apdu.getBuffer();shortp2=(short)getUnsignedByte(buf[ISO7816.OFFSET_P2]);n=(short)(buf[ISO7816.OFFSET_P1]*256+p2);//取p1,p2转化为一个数.short强制转换sum=(short)(Balance+n);if((n=MAX_BALANCE)&&(n0x00)){if((sum=MAX_BALANCE)&&(sum=0x00)){Balance=(short)(Balance+n);buf[0]=(byte)(Balance8);buf[1]=(byte)(Balance&0xff);apdu.setOutgoingAndSend((byte)0,(byte)2);}else{ISOException.throwIt((short)0x6102);}}else{ISOException.throwIt((short)0x6101);}}取款voidcredit(APDUapdu)//消费buf{///////////////////这里///if(!pin.isValidated())ISOException.throwIt(SW_VERIFICATION_REQUIRED);/////////////////////////////////shortm;byte[]buf=apdu.getBuffer();shortp2=(short)getUnsignedByte(buf[ISO7816.OFFSET_P2]);m=(short)(buf[ISO7816.OFFSET_P1]*256+p2);//取1,p2转化为一个数.short强制转换if((m=MAX_TRANSACTION_AMOUNT)&(m0)){if(Balancem){Balance=(short)(Balance-m);buf[0]=(byte)(Balance8);buf[1]=(byte)(Balance&0xff);apdu.setOutgoingAndSend((byte)0,(byte)2);}else{ISOException.throwIt((short)0x6104);}}else{ISOException.throwIt((short)0X6103);}}获取钱包余额publicvoidgetBalance(APDUapdu){byte[]buf=apdu.getBuffer();buf[0]=(byte)(Balance8);buf[1]=(byte)(Balance&0xff);apdu.setOutgoingAndSend((byte)0,(byte)2);}身份验证privatevoidverify(APDUapdu){byte[]buffer=apdu.getBuffer();bytebyteRead=(byte)(apdu.setIncomingAndReceive());if(pin.check(buffer,ISO7816.OFFSET_CDATA,byteRead)==false)ISOException.throwIt(SW_VERIFICATION_FAILED);}Process方法publicvoidprocess(APDUapdu){if(selectingApplet()){return;}byte[]buf=apdu.getBuffer();switch(buf[ISO7816.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);}}APDU发送NameCLAINSP1P2LcDataFieldLe(sizeofresponse)返回选择00a4........9000DEBIT000x01钱数00成功9000失败61016102CREDIT000x02钱数00成功9000失败61046103VERIFY000x03000003密码成功9000未经验证进行其他操作0x6301密码错误,或输入三次均错锁定6300GET_BALANCE000x05000000成功9000失败61046103测试数据1.cm/select|wallet1=00A404000777616C6C65743100选择功能(189100nsec)=9000成功Status:NoErrorcmsend0003000003100100验证身份,输入正确密码100100=0003000003100100(545900nsec)=9000成功Status:NoErrorcmsend0001271000充值100=0001271000(291700nsec)=27109000成功Status:NoErrorcmsend0005000000获取余额=0005000000(266400nsec)=27109000Status:NoErrorcm/select|wallet2撤销选择=00A404000777616C6C65743200(348700nsec)=9000..Status:NoError2.cm/select|wallet1=00A404000777616C6C65743100选择(253500nsec)=9000..Status:NoErrorcmsend0003000003100101=0003000003100101密码错误第一次(7044usec)=6300c.Status:Authenticationfailedcmsend0003000003100101=0003000003100101密码错误第2次(444000nsec)=6300c.Status:Authenticationfailedcmsend0003000003100101=0003000003100101密码错误第3次(365700nsec)=6300c.Status:Authenticationfailedcmsend0003000003100100=0003000003100100密码正确,但超三次了,无法再进入(250800nsec)=6300Status:Authenticationfailed3.cm/select|wallet1=00A404000777616C6C65743100选择(223200nsec)=9000Status:NoErrorcmsend0001271000=0001271000没有经过密码验证,无法进入充值(256000nsec)=6301Status:0x63014.充100花0元,不可以,6103花51,不可以,6103花50,剩50花50,剩0花1,不可以,6104充一元再冲100,101块再冲199,共300再冲1块,不可以,6102重置。冲301,不可以,6101冲0.不可以,6101关键代码安装publicstaticvoidinstall(byte[]bArray,shortbOffset,bytebLength){newWallet(bArray,bOffset,bLength);}选择publicbooleanselect(){if(pin.getTriesRemaining()==0)returnfalse;returntrue;}撤销选择publicvoiddeselect(){pin.reset();}存款voiddebit(APDUapdu)//充值{//////////这里//////////////if(!pin.isValidated())ISOException.throwIt(SW_VERIFICATION_REQUIRED);//////////////////////////////shortn,sum;byte[]buf=apdu.getBuffer();shortp2=(short)getUnsignedByte(buf[ISO7816.OFFSET_P2]);n=(short)(buf[ISO7816.OFFSET_P1]*256+p2);//取p1,p2转化为一个数.short强制转换sum=(short)(Balance+n);if((n=MAX_BALANCE)&&(n0x00)){if((sum=MAX_BALANCE)&&(sum=0x00)){Balance=(short)(Balance+n);buf[0]=(byte)(Balance8);buf[1]=(byte)(Balance&0xff);apdu.setOutgoingAndSend((byte)0,(byte)2);}else{ISOException.throwIt((short)0x6102);}}else{ISOException.throwIt((short)0x6101);}}取款voidcredit(APDUapdu)//消费buf{///////////////////这里///if(!pin.isValidated())ISOException.throwIt(SW_VERIFICATION_REQUIRED);/////////////////////////////////shortm;byte[]buf=apdu.getBuffer();shortp2=(short)getUnsignedByte(buf[ISO7816.OFFSET_P2]);m=(short)(buf[ISO7816.OFFSET_P1]*256+p2);//取1,p2转化为一个数.short强制转换if((m=MAX_TRANSACTION_AMOUNT)&(m0)){if(Balancem){Balance=(
本文标题:Java卡电子钱包实验报告
链接地址:https://www.777doc.com/doc-8143744 .html