命令APDU在结果中返回6985(不满足使用条件) [英] Command APDU returning 6985 (Conditions of use not satisfied) in result

查看:177
本文介绍了命令APDU在结果中返回6985(不满足使用条件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java读取智能卡.当我执行以下代码时,卡将因此返回6985(使用条件未得到满足).

I am working on reading a smart card in Java. When I execute the following code below, the card returns 6985 (Conditions of use not satisfied) as a result.

  TerminalFactory factory = TerminalFactory.getDefault();
  List<CardTerminal> terminals = factory.terminals().list();
  System.out.println("Terminals: " + terminals);

  if (terminals != null && !terminals.isEmpty()) {
   // Use the first terminal
   CardTerminal terminal = terminals.get(0);

   // Connect with the card
   Card card = terminal.connect("*");
   System.out.println("card: " + card);
   CardChannel channel = card.getBasicChannel();

   CommandAPDU commandAPDU = new CommandAPDU(0x00, 0xA4, 0x00, 0x0C,
   new byte[]{0002},0,0x01);

   ResponseAPDU responseCheck = channel.transmit(commandApdu);
   System.out.println(responseCheck.getSW1()+":"+responseCheck.getSW2()+":"+
   commandApdu.toString());

客户端提供的参数是:

  • CLA = 00
  • INS = A4
  • P1 = 00
  • P2 = 0C
  • LC = 02
  • 数据= XXXX(此处传递的数据是文件标识符),由于我要选择EF文件,因此客户端给定文件的EFID为0002

推荐答案

CommandAPDU commandAPDU = new CommandAPDU(0x00, 0xA4, 0x00, 0x0C, new byte[]{0002},0,0x01);

不会按照您的期望去做.

won't do what you expect it to do.

new byte[]{0002}将为您提供一个字节数组,其中一个字节的值为2.而且,,0,0x01);(最后两个参数)将使构造函数仅从DATA数组中选择该字节.因此,您的APDU如下所示:

new byte[]{0002} will give you a byte array with one byte of value 2. Also, the ,0,0x01); (last two parameters) will make the constructor only pick that one byte from the DATA array. So your APDU will look like this:


+------+------+------+------+------+------+------+
| CLA  | INS  | P1   | P2   | Lc   | DATA | Le   |
| 0x00 | 0xA4 | 0x00 | 0x0C | 0x01 | 0x02 | ---  |
+------+------+------+------+------+------+------+

这可能不是您所期望的.您是否要使用new byte[]{0, 2}?使用

This is probably not what you expected. Did you want new byte[]{0, 2} instead? Using

CommandAPDU commandAPDU = new CommandAPDU(0x00, 0xA4, 0x00, 0x0C, new byte[]{0, 2}, 256)

将产生以下APDU(请注意,存在Le并将其设置为0(Ne = 256);从DATA数组的大小自动推断出Lc):

would result in the following APDU (note that Le is present and set to 0 (Ne = 256); Lc is automatically infered from the size of the DATA array):


+------+------+------+------+------+-----------+------+
| CLA  | INS  | P1   | P2   | Lc   | DATA      | Le   |
| 0x00 | 0xA4 | 0x00 | 0x0C | 0x02 | 0x00 0x02 | 0x00 |
+------+------+------+------+------+-----------+------+

或使用

CommandAPDU commandAPDU = new CommandAPDU(0x00, 0xA4, 0x00, 0x0C, new byte[]{0, 2})

将导致以下APDU(请注意,Le不存在(Ne = 0;从DATA数组的大小自动推断出Lc)):

would result in the following APDU (note that Le is absent (Ne = 0); Lc is automatically infered from the size of the DATA array):


+------+------+------+------+------+-----------+------+
| CLA  | INS  | P1   | P2   | Lc   | DATA      | Le   |
| 0x00 | 0xA4 | 0x00 | 0x0C | 0x02 | 0x00 0x02 | ---  |
+------+------+------+------+------+-----------+------+

这篇关于命令APDU在结果中返回6985(不满足使用条件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆