To create an applet that can send and receive extended length APDUs:
javacardx.apdu.ExtendedLength
interface in your applet:
... import javacard.framework.*; import javacardx.apdu.ExtendedLength; ... public MyApplet extends Applet implements ExtendedLength { ... }
Applet.process(..)
method as you would with any other applets. For consistency, it is advisable that your process(..)
code begin like the one below:
public void process(APDU apdu) { byte[] buffer = apdu.getBuffer(); if (apdu.isISOInterindustryCLA()) { if (this.selectingApplet()) { return; } else { ISOException.throwIt (ISO7816.SW_CLA_NOT_SUPPORTED); } } switch (buffer[ISO7816.OFFSET_INS]) { case CHOICE_1: ... return; case CHOICE_2: ... ... default: ISOException.throwIt (ISO7816.SW_INS_NOT_SUPPORTED); } }
void receiveData(APDU apdu) { byte[] buffer = apdu.getBuffer(); short LC = apdu.getIncomingLength(); short recvLen = apdu.setIncomingAndReceive(); short dataOffset = apdu.getOffsetCdata(); while (recvLen > 0) { ... [process data in buffer[dataOffset]...] ... recvLen = apdu.receiveBytes(dataOffset); } // Done }
void sendData(APDU apdu) { byte[] buffer = apdu.getBuffer(); short LE = apdu.setOutgoing(); short toSend = ... if (LE != toSend) { apdu.setOutgoingLength(toSend); } while (toSend > 0) { ... [prepare data to send in APDU buffer] ... apdu.sendBytes(dataOffset, sentLen); toSend -= sentLen; } // Done }