JavaCard - AID没有保存?数组被最后一个元素覆盖

时间:2013-09-26 15:15:50

标签: arrays javacard

我在创建目录文件时遇到问题。我显然没有创建一个新的Object,只是参考 - 只是仍然不确定在哪里/为什么!

DirectoryFile[] arrayDF = new DirectoryFile[8];

现在我创建一个新的DF:

numapp++;
arrayDF[numApp] = new DirectoryFile(aid);

然后我就在循环中打印出来

APDU apdu = APDU.getCurrentAPDU();
apdu.setOutgoing();
apdu.setOutgoingLength((short) 21);

for (i = 2; i <= numApp; i++) {          
     apdu.sendBytesLong(arrayDF[i].getAID(), (short) 0, (short) 6);

}

其中numApp是Applications / DF的数量,从2开始,因为1是MasterFile。 for aid = a00000000001我得到

A0 00 00 00 00 01 90 00                         .........
Status: No Error

作为回应 for aid = a00000000002我得到了

A0 00 00 00 00 02 A0 00 00 00 00 02 90 00    ................
Status: No Error

for aid = a00000000003我得到了

A0 00 00 00 00 03 A0 00 00 00 00 03 A0 00 00 00 00 03 90 00    ................
    Status: No Error

因此,所有已保存的AID都会以某种方式被覆盖。 在DirectoryFile中,我执行以下操作

public DirectoryFile(byte[] aid) {
        super(aid);
        for (byte i = 0; i < activatedFiles.length; i++)
            activatedFiles[i] = false;

    }

其中super(aid)调用File.java的构造函数

     public abstract class File {
            public byte[] aid = new byte[6];

            public File (byte[] aid) {
                this.aid = aid; 
            }
            public byte[] getAID() {
                return aid;
            }
     }

我这样做的错误在哪里?

经过一些测试后,我至少发现类(DirectoryFile,File)应该可以正常工作:

 aDF[j] = new DirectoryFile(aid1);
      j++;
      aDF[j] = new DirectoryFile(aid2);
      j++;
      aDF[j] = new DirectoryFile(aid3);
      j++;
      aDF[j] = new DirectoryFile(aid4);
      j++;
      APDU apdu = APDU.getCurrentAPDU();
      apdu.setOutgoing();
      byte[] myi = new byte[1];
      apdu.setOutgoingLength((short) 28);
      for (j = 0; i < 4; i++) {      
        myi[0] = i;       
        apdu.sendBytesLong(myi, (short) 0, (short) 1);
        apdu.sendBytesLong(aDF[i].getAID(), (short) 0, (short) 6);

将打印

00 A0 00 00 00 00 01 01 A0 00 00 00 00 02 02 A0    ................
    00 00 00 00 03 03 A0 00 00 00 00 04 90 00          ..............
Status: No Error

1 个答案:

答案 0 :(得分:0)

您的File实现不正确,您首先生成一个包含六个字节的数组,但不是使用Util.arrayCopy()将AID复制到其中 - 您只需为传入的数组指定引用即可,抛出对先前生成的aid缓冲区的引用。因此,如果传入AID的值更改值,则File中的AID值也会更改。