Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Array of arrays in javacard

JavaCard Applet Development Related Questions and Answers.
Penneke
Posts: 10
Joined: Tue Mar 21, 2017 8:26 pm
Points :160
Contact:

Array of arrays in javacard

Post by Penneke » Sun May 21, 2017 8:15 pm

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.

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Array of arrays in javacard

Post by UNKNwYSHSA » Tue May 23, 2017 3:34 am

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

Penneke
Posts: 10
Joined: Tue Mar 21, 2017 8:26 pm
Points :160
Contact:

Re: Array of arrays in javacard

Post by Penneke » Tue May 23, 2017 3:59 pm

That's exactly what I was looking for. I'm very grateful :D

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Array of arrays in javacard

Post by UNKNwYSHSA » Thu May 25, 2017 4:54 am

Penneke wrote:That's exactly what I was looking for. I'm very grateful :D

:D
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 94 guests

JavaCard OS : Disclaimer