I have a java card and i write a small code to send APDU to java card. here when i am sending Init_Update command , m getting 0x6985 like:-
CMD -> 80 50 00 00 08 11 22 33 44 55 66 77 88
RES <- 6985
But when I am sending this command with other tool , it is giving required result like:-
Transmit: 80 50 00 00 08 []
11 22 33 44 55 66 77 88 ."3DUfw.
Card answered: 61 1C
My java code is working good for other java card I have. Could anybody tell me what can be cause of this different behavior..
// full java code
public static void main(String[] args) {
// TODO code application logic here
try
{
factory = TerminalFactory.getDefault();
terminals = factory.terminals().list();
terminal = terminals.get(0);
card = terminal.connect("*");
channel =card.getBasicChannel();
CommandAPDU cmdAPDU;
ResponseAPDU response;
byte[] select_isd = {(byte) 0x00,(byte) 0xA4,(byte) 0x04,(byte) 0x00,(byte) 0x08,(byte) 0xA0,(byte) 0x00,
(byte) 0x00,(byte) 0x00,(byte) 0x03,(byte) 0x00,(byte) 0x00,(byte) 0x00 };
cmdAPDU = new CommandAPDU(select_isd);
response = channel.transmit(cmdAPDU);
byte[] INIT_UPDATE = {(byte) 0x80,(byte) 0x50,(byte) 0x00,(byte) 0x00,(byte) 0x08,(byte) 0x11,(byte) 0x22,
(byte) 0x33,(byte) 0x44,(byte) 0x55,(byte) 0x66,(byte) 0x77,(byte) 0x88 };
cmdAPDU = new CommandAPDU(INIT_UPDATE);
response = channel.transmit(cmdAPDU);
}
catch( Exception ex)
{
}
}
Other tool log is look like:-
Card opened
12 bytes ATR received:
3B 68 00 00 00 73 C8 40 00 00 90 00
Transmit: 00 A4 04 00 08 [SELECT FILE]
A0 00 00 00 03 00 00 00 ........
Card answered: 61 12
Transmit: 00 C0 00 00 12 [GET RESPONSE]
Card answered: 90 00
6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 o..............e
01 FF ..
Transmit: 80 50 00 00 08 []
11 22 33 44 55 66 77 88 ."3DUfw.
Card answered: 61 1C
But when i run my java code I am getting 6985 for INIT_UPDATE command.
Please let me know if require any other information for my side..
==newly added=== I tried to run my script in JCOP shell, my script is like:-
/mode trace=on
/terminal
/atr
/send 80CAA08D05
/send 802E000014B555C94B0B2368B4840201808502032288020060
/send 80D8000000
/atr
/send 80500000081122334455667788
and it give me required result. Same i tried to implement in java , my new java code is look like:- =====New Updated JAVA Code===
factory = TerminalFactory.getDefault();
terminals = factory.terminals().list();
terminal = terminals.get(0);
card = terminal.connect("*");
channel =card.getBasicChannel();
CommandAPDU cmdAPDU;
ResponseAPDU response;
byte[] x = { (byte) 0x80, (byte) 0xCA, (byte) 0xA0,(byte) 0x8D,(byte)0x05};
byte[] y = { remove command for security reasons};
byte[] z = { (byte) 0x80, (byte) 0xD8, (byte) 0x00, (byte) 0x00, (byte) 0x00}; // it set default key
cmdAPDU = new CommandAPDU(x);
response = channel.transmit(cmdAPDU);
System.out.println(response.toString());
cmdAPDU = new CommandAPDU(y);
response = channel.transmit(cmdAPDU);
System.out.println(response.toString());
cmdAPDU = new CommandAPDU(z);
response = channel.transmit(cmdAPDU);
System.out.println(response.toString());
card.disconnect(true);
card = terminal.connect("*");
channel =card.getBasicChannel();
byte[] INIT_UPDATE = {(byte) 0x80,(byte) 0x50,(byte) 0x00,(byte) 0x00,(byte) 0x08,(byte) 0x11,(byte) 0x22,(byte) 0x33,(byte) 0x44,(byte) 0x55,(byte) 0x66,(byte) 0x77,(byte) 0x88 };
cmdAPDU = new CommandAPDU(INIT_UPDATE);
response = channel.transmit(cmdAPDU);
response
do you get for theselect_isd
command when executing your code? – Jacklighter