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

  • V5_366772
    了解作者
  • 50.2KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-23 11:30
    上传日期
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); } } } }
ambig.rar
内容介绍
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+AmbiqConst
评论
    相关推荐