从Java智能卡APDU收到的奇怪数据?

时间:2017-05-14 12:49:52

标签: java smartcard javacard apdu

我可以毫无问题地从智能卡发送大部分数据。我注意到我总是需要删除APDU中的前6个字节以获得真实数据。

但是,在发送一个特定数据时,很难知道数据在APDU中的位置。

这是Java智能卡模拟器的代码:

data = new byte[] {(byte)0x6302}; 
apdu.setOutgoing();
apdu.setOutgoingLength((short) data.length);
apdu.sendBytesLong(data, (short) 0, (short) data.length);

预计发送/接收的数据是:

  

{0X2}

但是,中间件响应APDU中收到的数据是:

  

responseApdu.getData():

     

{0x80,0x32,0x0,0x0,0x8,0x0,0x0,0x1,0x5c,0x6,0xf9,0x63,0x33,0x1,0x2,0x90,0x0}

我也尝试记录java卡模拟器发送的APDU;它是以下数据:

  

SendAPDU()数据(apdu.getBuffer()):

     

{0x2,0x32,0x0,0x0,0x8,0x0,0x0,0x1,0x5c,0x6,0xf9,0x63,0x33,0x0,.....(此点后全部为0x0)}

     

抵消CDATA:5

有人可以帮助我理解为什么发送的数据(或甚至在发送之前读取)与发送的实际数据有如此不同?它是某种填充物吗?如何发送原始数据?

1 个答案:

答案 0 :(得分:2)

将代码更改为:

data = new byte[] {(byte) 0x63, (byte) 0x02}; 
apdu.setOutgoing();
apdu.setOutgoingLength((short) data.length);
apdu.sendBytesLong(data, (short) 0, (short) data.length);

将发送数据字节{0x63,0x02}。

您在问题中提到的数据:

  1. 响应APDU数据为:
  2. responseApdu.getData():
    {0x80, 0x32, 0x0, 0x0, 0x8, 0x0, 0x0, 0x1, 0x5c, 0x6, 0xf9, 0x63, 0x33, 0x1, 0x2, 0x90, 0x0}
    

    表示命令数据为:{ 0x80, 0x32, 0x0, 0x0, 0x8, 0x0, 0x0, 0x1, 0x5c, 0x6, 0xf9, 0x63, 0x33, 0x1};,响应数据为:{ 0x2, 0x90, 0x0 };

    1. apdu缓冲区是:
    2. SendAPDU() data (apdu.getBuffer()):
      {0x2, 0x32, 0x0, 0x0, 0x8, 0x0, 0x0, 0x1, 0x5c, 0x6, 0xf9, 0x63, 0x33, 0x0, ..... (all 0x0 after this point)}
      Offset CDATA: 5
      

      表示将发送数据字节0x02(发送长度为1个字节),此字节后将发送SW 0x9000({0x90,0x00})。传出时不使用偏移CDATA。 APDU缓冲区中的其他数据字节是您的APDU命令,第一个字节由输出字节覆盖(这里只有1个字节,0x02)。

      注意: APDU.sendBytesLong的过程(数据,偏移,长度):

      1)。将具有偏移量和长度的数据复制到APDU缓冲区;

      2)。使用APDU缓冲区发送数据;

      3)。发送SW;