[英]JavaCard - AID not saved? array gets overwritten with the last element
I am encountering a problem when I create a Directory File. 创建目录文件时遇到问题。 I am obviously not creating a new Object, but only the reference - just still not sure where/why! 我显然不是在创建新的Object,而只是在创建引用-仍然不确定在哪里/为什么!
DirectoryFile[] arrayDF = new DirectoryFile[8];
now when I create a new DF: 现在,当我创建一个新的DF:
numapp++;
arrayDF[numApp] = new DirectoryFile(aid);
and right after that I simply print them out in a loop 然后我就将它们循环打印出来
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);
}
where numApp is the number of Applications/DFs, starting with 2, since 1 is the MasterFile. 其中numApp是应用程序/ DF的数量,从2开始,因为1是MasterFile。 for aid = a00000000001 I get 援助= a00000000001我得到
A0 00 00 00 00 01 90 00 .........
Status: No Error
as response for aid = a00000000002 I get 作为援助的响应= a00000000002我得到了
A0 00 00 00 00 02 A0 00 00 00 00 02 90 00 ................
Status: No Error
for aid = a00000000003 I get 援助= a00000000003我得到
A0 00 00 00 00 03 A0 00 00 00 00 03 A0 00 00 00 00 03 90 00 ................
Status: No Error
So all the already saved AIDs get somehow overwritten. 因此,所有已经保存的AID都会以某种方式被覆盖。 In DirectoryFile I do as follows 在DirectoryFile中,我按如下操作
public DirectoryFile(byte[] aid) {
super(aid);
for (byte i = 0; i < activatedFiles.length; i++)
activatedFiles[i] = false;
}
where super(aid) calls the constructor of File.java 其中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;
}
}
Where is my mistake in doing this? 我这样做的错误在哪里?
After a bit more testing I at least found out that the classes (DirectoryFile, File) should work just fine: 经过更多测试之后,我至少发现类(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);
will print 将打印
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
Your File
implementation is not correct, you first generate an array of six bytes, but instead of copying the AID into it - using Util.arrayCopy()
- you simply assign it the reference to the passed in array, throwing a way the reference to the previously generated aid
buffer. 您的File
实现不正确,您首先生成了一个六个字节的数组,但没有使用Util.arrayCopy()
将AID复制到其中,而是简单地将其引用分配给传入的数组,从而抛出了对先前生成的aid
缓冲区。 So if the values of the passed in AID changes value, the value of the AID in File
also changes. 因此,如果传入的AID的值更改了值,则File
中的AID的值也会更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.