Failed to send Extended APDU

前端 未结 2 850
长发绾君心
长发绾君心 2020-12-17 06:47

I have a big byte array (it\'s 320 bytes) on my Java Card and I want to send its data in one APDU response.

So, I implemented ExtendedLength

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 06:55

    An unhandled exception was thrown by your applet because you called sendBytes() without calling setOutgoing() and setOutgoingLength() first.

    Also, I haven't really counted the length of longData but make sure that its length is a multiple of 32 bytes otherwise Util.arrayCopyNonAtomic() will throw an ArrayIndexOutOfBoundsException and will make your applet throw 6F00.

    Maybe you can try it this way:

        apdu.setOutgoing();
        apdu.setOutgoingLength(toSend);
        while (toSend > 0) {
            Util.arrayCopyNonAtomic(longData, (short) (counter * 32), buffer, (short) 0, (short) 32);
            apdu.sendBytes((short) 0, (short) 32);
            toSend = (short) (toSend - 32);
            counter = (byte) (counter + 1);
        }
    

    Or much better, instead of doing a while loop:

        apdu.setOutgoing();
        apdu.setOutgoingLength(toSend);
        apdu.sendBytesLong(longData, (short)0, toSend);
    

提交回复
热议问题