简体   繁体   English

如何使用“过程”方法将“安装”方法参数发送到读卡器?

[英]How to send “install” method arguments to the card reader using “process” method?

I wrote an applet for my java card and I want to send the arguments of install method to the CAD. 我为Java卡编写了一个applet,我想将install方法的参数发送给CAD。 so I defined two static variables named theArray and arrayLength in my applet. 所以我定义的命名theArrayarrayLength在我的小程序两个静态变量。 And after that I made a copy of the install method arguments inside the body of that method. 之后,我在该方法的主体内复制了install方法参数。 Finally I tried to return this variables to CAD in the process method. 最后,我尝试在process方法中将此变量返回给CAD。 But in the response of SELECT command, the card returns SW=6F00 . 但是在SELECT命令的响应中,卡返回SW=6F00

package bArrayAccessibilty;

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

public class BArrayReturner extends Applet {

    public static byte[] theArray;
    public static short arrayLength;

    private BArrayReturner() {
    }

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

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


    }

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

Note that, Initialization of the static fields, doesn't change anything. 请注意,静态字段的初始化不会更改任何内容。
I mean, I tried this lines in the class body also : 我的意思是,我也在课堂上尝试了以下内容:

public static byte[] theArray=null;
public static short arrayLength=0;

But nothing changed. 但是什么都没有改变。

What is wrong in my program? 我的程序有什么问题?

The install method gets called when you install te applet. 安装小程序时将调用install方法。
The process method gets called when you (select first and)send a command to an instantiated/installed applet. 当您(首先选择并)将命令发送到实例化/安装的applet时,将调用process方法。
This means that the install method will get called first and thus: 这意味着将首先调用install方法,因此:
your first error is tat you want to write to an uninitialized array(theArray == null) 您的第一个错误是tat您想写入未初始化的数组(theArray == null)
your second error is the wrong parameters for Util.arrayCopyNonAtomic(take care for the offsetParameter handed over by the install method) 您的第二个错误是Util.arrayCopyNonAtomic的参数错误(请注意install方法移交的offsetParameter)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM