JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
Array of arrays in javacard
Array of arrays in javacard
Hi, I need to save several messages into my Javacard (lets say 40 or 50 of 500 bytes aprox. variable sized -less than 30KB in total-). After been verified by PIN I need to randomly response one of the messages that hasn't been already used so that I thougth i could store all byte array messages in another array or structure to manage them.
Is it possible in Javacard and how should i do this?
If not and I need to create 40 or 50 byte array variables... Is it possible to save a reference to each array or something to let me choose one of them randomly or refer to it?
Thanks in advance.
Is it possible in Javacard and how should i do this?
If not and I need to create 40 or 50 byte array variables... Is it possible to save a reference to each array or something to let me choose one of them randomly or refer to it?
Thanks in advance.
- UNKNwYSHSA
- Posts: 630
- Joined: Thu May 21, 2015 4:05 am
- Points :3055
- Contact:
Re: Array of arrays in javacard
Refer to code following:
Code: Select all
package testObjectArray;
import javacard.framework.*;
public class testObjectArray extends Applet
{
Object[] messages;
testObjectArray() {
messages = new Object[3];
messages[0] = new byte[] { 'w', 'w', 'w', '.', 'J', 'a', 'v', 'a', 'C', 'a', 'r', 'd', 'O', 'S', '.', 'c', 'o', 'm' };
messages[1] = new byte[] { 'J', 'a', 'v', 'a', 'C', 'a', 'r', 'd', 'O', 'S', '@', 'g', 'm', 'a', 'i', 'l', '.', 'c', 'o', 'm' };
messages[2] = new byte[] { 'J', 'a', 'v', 'a', 'C', 'a', 'r', 'd', 'F', 'o', 'r', 'u', 'm' };
}
public static void install(byte[] bArray, short bOffset, byte bLength)
{
new testObjectArray().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu)
{
if (selectingApplet())
{
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS])
{
case (byte) 0x00:
JCSystem.requestObjectDeletion();
break;
case (byte) 0x01:
short message_index = (short) (buf[ISO7816.OFFSET_P1] & 0xFF);
if (message_index >= (short) messages.length) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
byte[] message = (byte[]) messages[message_index];
apdu.setOutgoing();
apdu.setOutgoingLength((short) message.length);
apdu.sendBytesLong(message, (short) 0, (short) message.length);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
sense and simplicity
Re: Array of arrays in javacard
That's exactly what I was looking for. I'm very grateful 

- UNKNwYSHSA
- Posts: 630
- Joined: Thu May 21, 2015 4:05 am
- Points :3055
- Contact:
Re: Array of arrays in javacard
Penneke wrote:That's exactly what I was looking for. I'm very grateful

sense and simplicity
Who is online
Users browsing this forum: No registered users and 58 guests