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.

Is it possible to send long bytes APDU (exceed 256)?

JavaCard Applet Development Related Questions and Answers.
jcfarmer
Posts: 3
Joined: Thu Apr 19, 2018 6:30 am
Points :50
Contact:

Is it possible to send long bytes APDU (exceed 256)?

Post by jcfarmer » Sat Apr 28, 2018 8:08 am

How to send a very long data APUD into a java card (exceed 256 or said the max data length can exceed 261). What is the software you used?
And the similar question how to send a very long data APUD from a java card to the terminal software or application.How to do that? Any sample codes?

wumindejia
Posts: 55
Joined: Thu Sep 22, 2016 5:05 am
Points :784
Contact:

Re: Is it possible to send long bytes APDU (exceed 256)?

Post by wumindejia » Thu May 03, 2018 2:19 am

You can use JCIDE to develop the applet of the javacard.

Your applet shall extends ExtendedLength interface.
Please refer to this example: https://javacardos.com/wiki/javacard-ap ... munication

applet :
public class EIDApplet extends Applet implements ExtendedLength{}

function:
public short receiveAPDU(APDU apdu, byte src[], short Lc, byte dest[]) {
short bytesReceived = (short)0;

bytesReceived = apdu.setIncomingAndReceive();
if (Lc == (short)0x00) {
short received = (short)0;
short dataLength = (short)0;

dataLength = Util.getShort(src, Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA));
if ((dataLength < (short)0)
|| (dataLength < bytesReceived)){
ISOException.throwIt((short)0x6700);
}

bytesReceived = abs((short)(bytesReceived + ISO7816.OFFSET_EXT_CDATA));
Util.arrayCopyNonAtomic(src, (short)0, dest, (short)0, bytesReceived);
dataLength = (short)(dataLength + ISO7816.OFFSET_EXT_CDATA);
if(dataLength > dest.length){
Error.wrong6700_P3Error();
}

while (bytesReceived < dataLength)
{
received = apdu.receiveBytes((short)0);
Util.arrayCopyNonAtomic(src, (short)0, dest, bytesReceived, received);
bytesReceived += received;
if ((apdu.getCurrentState() == APDU.STATE_FULL_INCOMING) &&
((short)bytesReceived != dataLength)){
ISOException.throwIt((short)0x6700);
}
}

src = dest;
Lc = Util.getShort(src, Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA));
apdu_offset[0] = Util.makeShort((byte)0x00, ISO7816.OFFSET_EXT_CDATA);
}
else
{
Util.arrayCopyNonAtomic(src, (short)0x00, dest, (short)0x00, (short)(Lc+5));
apdu_offset[0] = Util.makeShort((byte)0x00, ISO7816.OFFSET_CDATA);
}

return Lc;
}


public void sendAPDU(APDU apdu, byte buffer[], short offset, short length, boolean hasLe) {
short Le = (short)0x00;
short t0Max = (short)32767;
short sendlength = (short)0x00;

if (hasLe == true) {
Le = (short)0x00;
}
else {
Le = apdu.setOutgoing();
}

if (length > t0Max) {
ISOException.throwIt((short)0x6700);
}

if ((Le == (short)0x00) || (Le == (short)256) || (Le == t0Max)) {
Le = length;
}
else if (Le > (short)length) {
if (APDU.getProtocol() == APDU.PROTOCOL_T1) {
ISOException.throwIt((short)0x6700);
}
else if (APDU.getProtocol() == APDU.PROTOCOL_T0) {
ISOException.throwIt(Util.makeShort((byte)0x6C, (byte)length));
}
else
{
Le = length;
}
}
else {
Le = length;
}

apdu.setOutgoingLength(Le);
while (Le > (short)0) {
sendlength = (Le < (short)256) ? Le : (short)256;
apdu.sendBytesLong(buffer, offset, sendlength);
offset += sendlength;
Le -= sendlength;
}
}

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 31 guests

JavaCard OS : Disclaimer