Would anyone like to help me solve the problem of my card applet?
Hi,
Recently I wrote a Java card applet to store array of bytes into my card.
When I send APDU, it always sends back "6F 00",which means: No precise diagnosis.
Here is the code of my applet:
/**
*
*/
package cn.ac.sinap.baoqiang.fileaccess;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;
/**
* @author baoqiang
*
*/
publicclass FileAccessextends Applet{
/*
* APDU define
*/
finalstaticbyte CLA = (byte) 0x80;
finalstaticbyte WRITE = (byte) 0xA0;
finalstaticbyte READ = (byte) 0xA1;
finalstaticbyte DELETE = (byte) 0xA2;
/*
* Maximum size of file
*/
publicstaticfinalshort MAX_FILE_SIZE = (short) 240;
/*
* Bytes array used to hold file content
*/
privatebyte[] fileData;
/*
* File Size
*/
privateshort fileSize;
publicstaticvoid install(byte[] bArray,short bOffset,byte bLength){
// GP-compliant JavaCard applet registration
new FileAccess().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
publicvoid process(APDU apdu){
// Good practice: Return 9000 on SELECT
if (selectingApplet()){
return;
}
byte[] buf = apdu.getBuffer();
if (buf[ISO7816.OFFSET_CLA] != (byte) 0x80)
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
switch (buf[ISO7816.OFFSET_INS]){
case WRITE:
writeFile(apdu);
break;
case READ:
readFile(apdu);
break;
case DELETE:
deleteFile(apdu);
break;
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
privatevoid writeFile(APDU apdu){
byte[] buf = apdu.getBuffer();
fileSize = (short) buf[ISO7816.OFFSET_LC];
if (fileSize > MAX_FILE_SIZE){
// File Size exceeds MAX_FILE_SIZE: 60 00
buf[0] = (byte) 0x60;
buf[1] = (byte) 0x00;
apdu.setOutgoingAndSend((short) 0, (short) 2);
return;
}
Util.arrayCopy(buf, (short) 0, fileData, (short) 0, (short) fileSize);
// File write success
buf[0] = (byte) fileSize;
apdu.setOutgoingAndSend((short) 0, (short) 1);
}
privatevoid readFile(APDU apdu){
byte[] buf = apdu.getBuffer();
if (buf[ISO7816.OFFSET_P1] != 0x00 || buf[ISO7816.OFFSET_P2] != 0x00
|| buf[ISO7816.OFFSET_LC] != 0x00){
// Invalid Argument: 60 01
buf[0] = 0x60;
buf[1] = 0x01;
apdu.setOutgoingAndSend((short) 0, (short) 2);
return;
}
Util.arrayCopy(fileData, (short) 0, buf, (short) 0, (short) fileSize);
apdu.setOutgoingAndSend((short) 0, (short) fileSize);
}
privatevoid deleteFile(APDU apdu){
byte[] buf = apdu.getBuffer();
if (buf[ISO7816.OFFSET_P1] != 0x00 || buf[ISO7816.OFFSET_P2] != 0x00
|| buf[ISO7816.OFFSET_LC] != 0x00){
// Invalid Argument: 60 01
buf[0] = 0x60;
buf[1] = 0x01;
apdu.setOutgoingAndSend((short) 0, (short) 2);
return;
}
fileData =null;
fileSize = (short) 0;
// Delete success: 00
buf[0] = 0x00;
apdu.setOutgoingAndSend((short) 0, (short) 1);
}
}
When I send 80A000000101, which mean I want to store an byte array of one byte--"0x01" into my card , it sends back "6F 00".
Any comment will be appricieated!

