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.

How to let APDU buffer accept 200 bytes of data

JavaCard Applet Development Related Questions and Answers.
Asineshjil
Posts: 13
Joined: Wed Sep 16, 2015 10:54 pm
Points :60
Contact:

How to let APDU buffer accept 200 bytes of data

Post by Asineshjil » Sat Oct 17, 2015 2:26 am

According to the javadoc:
The APDU class maintains a byte array buffer which is used to transfer incoming APDU header and data bytes as well as outgoing data. The buffer length must be at least 133 bytes ( 5 bytes of header and 128 bytes of data ).

I need the buffer read and store the data with length 200 bytes. But the APDU buffer only accepts the first 128 bytes of the data.

What can I do now to let the buffer accept the rest bytes of data?
What is the specific meaning of this sentence "The buffer length must be at least 133 bytes ( 5 bytes of header and 128 bytes of data )."? Hope someone help me out.
Java card newbie :evil:

User avatar
Larson
Posts: 18
Joined: Wed May 20, 2015 3:56 am
Points :30
Contact:

Re: How to let APDU buffer accept 200 bytes of data

Post by Larson » Tue Oct 20, 2015 5:46 am

To read incoming data more than 128 bytes you may need to call APDU.receiveBytes() to accept the rest vytes of data.

Similarly, for sending data, APDU.sendBytes() might be needed to send longer data.

Bob2002
Posts: 36
Joined: Wed Jul 29, 2015 10:50 pm
Points :1218
Contact:

Re: How to let APDU buffer accept 200 bytes of data

Post by Bob2002 » Tue Oct 20, 2015 6:26 am

Code: Select all

     /**
     * Processes an incoming APDU.
     * @see APDU
     * @param apdu the incoming APDU
     * @exception ISOException with the response bytes per ISO 7816-4
     */
    public void process(APDU apdu)
    {
        byte buffer[] = apdu.getBuffer();

        short bytesRead = apdu.setIncomingAndReceive();
        short echoOffset = (short)0;

        while ( bytesRead > 0 ) {
            Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echoBytes, echoOffset, bytesRead);
            echoOffset += bytesRead;
            bytesRead = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
        }

        apdu.setOutgoing();
        apdu.setOutgoingLength( (short) (echoOffset + 5) );

        // echo header
        apdu.sendBytes( (short)0, (short) 5);
        // echo data
        apdu.sendBytesLong( echoBytes, (short) 0, echoOffset );
    }


Bob2002
Posts: 36
Joined: Wed Jul 29, 2015 10:50 pm
Points :1218
Contact:

Re: How to let APDU buffer accept 200 bytes of data

Post by Bob2002 » Tue Oct 20, 2015 6:35 am

Code: Select all

       ...
  byte[] buffer = apdu.getBuffer();
  short bytes_left = (short) buffer[ISO.OFFSET_LC];
  short readCount = apdu.setIncomingAndReceive();
  while (bytes_left > 0) {
  // Process received data in buffer; copy chunk to temp buf.
  Util.arrayCopy(buffer, ISO.OFFSET_CDATA, tbuf, 0, readCount);
  bytes_left -= readCount;
  // Get more data
  readCount = apdu.receiveBytes(ISO.OFFSET_CDDATA);
  }
  ...
  

Asineshjil
Posts: 13
Joined: Wed Sep 16, 2015 10:54 pm
Points :60
Contact:

Re: How to let APDU buffer accept 200 bytes of data

Post by Asineshjil » Thu Oct 22, 2015 5:41 am

Use these two methods :receiveBytes() and sendBytes() can solve my problem. I got it. Thanks for all the kind help.
Java card newbie :evil:

Hernrye
Posts: 2
Joined: Sat Feb 09, 2019 6:25 am
Points :20
Contact:

Re: How to let APDU buffer accept 200 bytes of data

Post by Hernrye » Sat Feb 09, 2019 6:27 am

Use these two methods :receiveBytes() and sendBytes() can solve my problem. I got it. Thanks for all the kind help.

Hernrye
Posts: 2
Joined: Sat Feb 09, 2019 6:25 am
Points :20
Contact:

Re: How to let APDU buffer accept 200 bytes of data

Post by Hernrye » Sat Feb 09, 2019 6:28 am

Use these two methods :receiveBytes() and sendBytes() can solve my problem. I got it. Thanks for all the kind help.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: Google [Bot] and 54 guests

JavaCard OS : Disclaimer