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

Strange data received from java smart card 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);

预计sent/received的数据是:

{0x2}

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

responseApdu.getData():

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

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

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

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

将代码更改为:

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数据为:
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 缓冲区是:
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(data, offset, length) 的过程:

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

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

3).发送软件;