I'm trying to set the CommandAPDU buffer with a byte array. However, if the length is >7, it throws the following error:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid APDU: length=8, b1=1 at javax.smartcardio.CommandAPDU.parse(CommandAPDU.java:318) at javax.smartcardio.CommandAPDU.(CommandAPDU.java:98) at terminal.Main.main(Main.java:78)
My code:
byte terminal = 0x00;
byte instruction = 0x01;
byte [] msg = {0x01,0x00,0x01,0x00};
byte [] fullmsg = new byte[msg.length + 4];
System.arraycopy(new byte []{terminal}, 0, fullmsg, 0, 1);
System.arraycopy(new byte [] {instruction}, 0, fullmsg, 1, 1);
System.arraycopy(new byte [] {0,0}, 0, fullmsg, 2, 2);
System.arraycopy(msg, 0, fullmsg, 4, msg.length);
CommandAPDU cmdapdu = new CommandAPDU(fullmsg);
Can someone help me out?
offsetvariable (and++or+= 2) 2. use constants for specific byte values (also for use within vlp's answer) and 3. please write a comment on what the code line is doing, because currently it is not easy to extract any meaning from the code. And the code failed because you forgot to write the fifthLcbyte which encodes the length of the command data, known asNc. - Maarten Bodewes