Search code examples
appletjavacardapdu

Unable to send 128 Bytes data from Javacard but can send 127 Bytes as a response to APDU command when using sendBytesLong()


While sending data from javacard in the form APDU commands using the apdu.sendBytesLong() Function, I am able to send 127 bytes data as response but 128 bytes data give error code 6f00(SW_UNKNOWN). Why is this happening and can anybody suggest the way around without splitting the data into two apdu commands.

le = apdu.setOutgoing();
            if(le != 128)
                ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
apdu.setOutgoingLength((byte)le);
apdu.sendBytesLong(mod_PkAIKR,(short)0, le);

where mod_PkAIKR is an byte array of 128 bytes.

Thank you


Solution

  • Change apdu.setOutgoingLength((byte)le); to apdu.setOutgoingLength(le);

    1. The parameter type of api apdu.setOutgoing() is short, it didn't needs type convert.
    2. If you convert le to type byte, the parameter value will be a nagative. the value of (byte) 128 is -128.