Page 1 of 1

How to send the arguments of install() method to smart card reader

Posted: Tue Dec 01, 2015 2:15 am
by conliaOdk
I have just finished an applet. In applet, I want to send the arguments of install() method to smart card reader.

Code: Select all

package bArraytest;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import javacard.framework.Util;

public class bArrayreturn extends Applet {
    // define two static variables
    public static byte[] theArray;
    public static short arrayLength;

    private bArrayreturn() {
    }

    public static void install(byte bArray[], short bOffset, byte bLength)
            throws ISOException {

        new bArrayreturn().register();
        bArrayreturn.arrayLength=(short)bArray.length;
        Util.arrayCopyNonAtomic(bArray, (short)0,bArrayreturn.theArray , (short) 0, bArrayreturn.arrayLength);   


    }

    public void process(APDU apdu) throws ISOException {
        byte[] buffer=apdu.getBuffer();
        Util.arrayCopyNonAtomic(bArrayreturn.theArray, (short)0,buffer , (short) 0, bArrayreturn.arrayLength);
        apdu.setOutgoingAndSend((short)0, (short)255);
    }


I defined two static variables named theArray and arrayLength in my applet. I tried to return variables to card reader in the process method. But in the response of SELECT command, the card returns 6F00.
Am I doing something wrong in my applet? How can I modify my code to make my applet work well? tnx

Re: How to send the arguments of install() method to smart card reader

Posted: Wed Dec 02, 2015 8:43 am
by horse dream
It seems that you want to write to an uninitialized array(theArray == null). For this, you can initialize with theArray = new byte[length]
And you also made the wrong parameters for Util.arrayCopyNonAtomic.