JavaCard Applet Development Related Questions and Answers.
-
Diorin
- Posts: 18
- Joined: Thu Nov 26, 2015 4:08 am
- Points :151
-
Contact:
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:
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
Users browsing this forum: No registered users and 19 guests
JavaCard OS : Disclaimer
Board Disclaimer
The views and comments posted in these fora are personal and do not necessarily represent the those of the Management of JavaCard OS.
The Management of JavaCard OS does not, under any circumstances whatsoever, accept any responsibility for any advice, or recommentations, made by, or implied by, any member or guest vistor of JavaCard OS that results in any loss whatsoever in any manner to a member of JavaCard OS, or to any other person.
Furthermore, the Management of JavaCard OS is not, and cannot be, responsible for the content of any other Internet site(s) that have been linked to from JavaCard OS.