Here is the updated code.
It is working fine at my end on JCIDE.
package appServer
- ServerApplet.java
package appServer;
import javacard.framework.AID;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Shareable;
public class ServerApplet extends Applet implements ServerAppBankInterface
{
public ServerApplet(byte[] bArray, short bOffset, byte bLength) {
register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public Shareable getShareableInterfaceObject(AID clientID, byte parameter) {
byte[] tempAID = {(byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01,(byte)0xAA};
if ((clientID.equals(tempAID,
(short)0,
(byte)tempAID.length)) == false)
return null;
else
return this;
}
public boolean select() {
return true;
}
public static void install(byte[] bArray, short bOffset, byte bLength) {
// GP-compliant JavaCard applet registration
new ServerApplet(bArray, bOffset, bLength);
}
public void process(APDU apdu) {
// Good practice: Return 9000 on SELECT
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
break;
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
public short getSavedMoneyInBank() {
// TODO Auto-generated method stub
return 0;
}
}
- ServerAppBankInterface.java
package appServer;
import javacard.framework.Shareable;
public interface ServerAppBankInterface extends Shareable {
//public void saveMoneyInBank(short amount);
public short getSavedMoneyInBank();
}
package appClient
1.Client Applet
package appClient ;
import appServer.*;
import javacard.framework.AID;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.JCSystem;
import javacard.framework.Shareable;
import javacard.framework.Util;
public class ClientApplet extends Applet
{
ServerAppBankInterface sio;
byte[] serverAID = {(byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02,(byte)0xBB};
public ClientApplet() {
// TODO Auto-generated constructor stub
}
public static void install(byte[] bArray, short bOffset, byte bLength) {
// GP-compliant JavaCard applet registration
new ClientApplet().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
public void process(APDU apdu) {
// Good practice: Return 9000 on SELECT
if (selectingApplet()) {
return;
}
byte[] buf = apdu.getBuffer();
byte cla = buf[ISO7816.OFFSET_CLA];
if ((cla != ISO7816.CLA_ISO7816) && (cla != (byte) 0x10))
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
AID svrAid = JCSystem.lookupAID(serverAID,
(short)0,
(byte)serverAID.length);
if (svrAid == null) {
// Cannot find the serverAID AID
ISOException.throwIt((short)0x0010);
}
sio = (ServerAppBankInterface)JCSystem.getAppletShareableInterfaceObject(svrAid, (byte)0);
if (sio == null){
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
ServerAppBankInterface bankInterface = (ServerAppBankInterface) sio;
bankInterface.getSavedMoneyInBank();
break;
default:
// Good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}