JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html

A problem about storing data larger than 128 bytes in javacard

JavaCard Applet Development Related Questions and Answers.
Diorin
Posts: 18
Joined: Thu Nov 26, 2015 4:08 am
Points :151
Contact:

A problem about storing data larger than 128 bytes in javacard

Post by Diorin » Wed Dec 23, 2015 2:02 am

I run into a problem when storing data larger than 128 bytes in javacard.

part of my code

Code: Select all

private void Write1(APDU apdu) throws ISOException
{
    apdu.setIncomingAndReceive();
    byte[] apduBuffer = apdu.getBuffer();
    byte j = (byte)apduBuffer[4];       // Return incoming bytes lets take 160
    Buffer1 = new byte[j];              // initialize a array with size 160
    for (byte i=0; i<j; i++)
        Buffer1[(byte)i] = (byte)apduBuffer[5+i];
}


When I run my applet, it returns sw=0x6F00. How can I modify my code so that it can work well?

Tarantino
Posts: 101
Joined: Wed Aug 19, 2015 1:56 am
Points :478
Contact:

Re: A problem about storing data larger than 128 bytes in javacard

Post by Tarantino » Wed Dec 30, 2015 10:10 pm

There is some problems in your code.
-You are creating a new buffer Buffer1 on every call of your Write1 method. On JavaCard there is usually no automatic garbage collection - therefore memory allocation should only be done once when the app is installed. If you only want to process the data in the adpu buffer just use it from there. And if you want to copy data from one byte array into another better use javacard.framework.Util.arrayCopy().

-You are calling apdu.setIncomingAndReceive(); but ignore the return value. The return value gives you the number of bytes of data you can read.
The greatest glory in living lies not in never falling, but in rising every time we fall.--Nelson Mandela

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 19 guests

JavaCard OS : Disclaimer