如何让卡的PSE读取RID或AIP或卡号

时间:2017-07-01 13:32:27

标签: java smartcard

我有一张智能卡,如下图所示。该卡位于卡读卡器中,卡在服务器上。它曾用于验证用户身份 在他下载数据之前。

我正在尝试获取智能卡的卡号或序列号或RID。除了以下其他信息之外,我还可以从中获取ATR。

ATR:

 3b 9f 96 c0 0a 31 fe 45 43 54 31 69 0b 01 00 01 00 00 00 00 00 00 00 0d

在这个问题中

SmartCardIO EMV Reader, find my card type with only the ATR number

有人提到AID (Application ID) = RID(Registered Application ID) || PIX (Property Application Extension)

此页面说明哪些信息包含ATR。

https://flomio.com/forums/topic/list-of-apdu-codes/

                              Answer-To-Reset (ATR)
Init| T0| TD1| TD2| T1| Tk|  Len |      RID      | Std | Card |  RFU       | TCK
Hdr |   |    |    |   |   |      |               |     | Name |            |   
 3B | 8F| 80 | 01 | 80| 4F|  0C  | A0 00 00 03 06| 03  | 00 03| 00 00 00 00| 68

当我尝试获取PSE时,我得到的6a86也是错误的P1 / P2。 当我试图获得PPSE时,我得到6700 - >错误的长度。

command               : 00 A4 04 00 0E 31 50 41 59 2E 53 59 53 2E 44 44 46 30 31
response without data : 6a 86
command               : 00 A4 04 00 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31 00
response without data : 67 00

http://techqa.info/programming/question/36297722/SmartCardIO-EMV-Reader--find-my-card-type-with-only-the-ATR-number

我也试过这个选项:

// byte[] pseFileName = "1PAY.SYS.DDF01".getBytes(); //PSE
byte[] pseFileName = "2PAY.SYS.DDF01".getBytes(); // PPSE
CommandAPDU command = new CommandAPDU(0x00, 0xA4, 0x04, 0x00, pseFileName);

我目前获得的信息:

Terminals list: [PC/SC terminal Generic Smart Card Reader Interface 0]
ATR:  3b 9f 96 c0 0a 31 fe 45 43 54 31 69 0b 01 00 01 00 00 00 00 00 00 00 0d
command               : 00 a4 02 0c 02 00 02
response without data : 90 00
command               : 00 b0 00 00 09
response with data:   : 00 00 01 98 fa 03 16 14 ad
command               : 00 a4 04 0c 06 ff 54 41 43 48 4f
response without data : 90 00
command               : 00 a4 02 0c 02 05 01
response without data : 90 00
command               : 00 b0 00 00 01
response with data:   : 04
command               : 00 22 c1 b6 0a 83 08 00 00 00 05 09 02 ff a1
response without data : 90 00
command               : 00 88 00 00 10 e9 96 79 ec 74 27 e6 50 00 00 00 05 09 02 ff a1 80
response with data:   : 32 a9 bf e6 91 18 8d c8 34 87 d8 c5 6d 78 f3 90 24 db 98 60 37 f0 05 f3 1f 22 24 65 27 90 43 ff 4f ec 4f ae 7c 2e d9 4c 6d a0 bc 14 9a af df fb 81 0b 5a 4f 4d 1d ee df 38 3b 0d dd 63 7d 22 69 77 27 5b f3 0d ce 51 a3 5c fc 7f 4a fc 8c f1 da d9 ce c7 9b a1 23 e0 e6 1d b0 73 e8 3b 4b 8a 60 38 e8 0d ad 30 80 12 ef d3 76 72 75 95 2f af 09 10 e0 37 78 25 84 2e 19 0e 2e 17 9e 9d de 34 b7

如何获得卡上的卡号(5b)以及RID和AID?为什么我可以获得我的卡的PSE?

enter image description here

代码

import java.util.ArrayList;
import java.util.List;

import javax.smartcardio.ATR;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import javax.smartcardio.TerminalFactory;
import javax.xml.bind.DatatypeConverter;


public class CardIdTest {

    public static void main(String[] args) {

        try {
            TerminalFactory factory = TerminalFactory.getDefault();
            List<CardTerminal> terminals;
            terminals = factory.terminals().list();
            CardTerminal terminal = terminals.get(0);
            Card card = terminal.connect("T=1");
            System.out.println("Terminals list: " + terminals);
            ATR atr = card.getATR();
            byte[] atrArray = atr.getBytes();
            String atrHex = CardIdTest.printData(atrArray);
            System.out.println("ATR: " + atrHex);
            CardChannel channel = card.getBasicChannel();

            String command1 = "00 a4 02 0c 02 00 02"; // select file
            String command2 = "00 b0 00 00 09"; // length 19 works at the end instead of 09. // read binary
            String command3 = "00 a4 04 0c 06 ff 54 41 43 48 4f";
            String command4 = "00 a4 02 0c 02 05 01"; //
            String command5 = "00 b0 00 00 01";
            String command6 = "00 22 c1 b6 0a 83 08 00 00 00 05 09 02 ff a1";
            String command7 = "00 88 00 00 10 e9 96 79 ec 74 27 e6 50 00 00 00 05 09 02 ff a1 80";

            String pseString = "00 A4 04 00 0E 31 50 41 59 2E 53 59 53 2E 44 44 46 30 31";
            String ppseString = "00 A4 04 00 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31 00";

            List<String> list = new ArrayList<String>();
            // list.add(command1);
            // list.add(command2);
            // list.add(command3);
            // list.add(command4);
            // list.add(command5);
            // list.add(command6);
            // list.add(command7);
            list.add(pseString);
            list.add(ppseString);

            for (String item : list) {
                String commandWithoutSpace = item.replace(" ", "");
                byte[] apdu = DatatypeConverter.parseHexBinary(commandWithoutSpace);
                CommandAPDU command = new CommandAPDU(apdu);
                ResponseAPDU responseAPDU = channel.transmit(command);
                byte[] reponseData = responseAPDU.getData();
                String response = responseAPDU.toString();
                if (reponseData.length > 0) {
                    String dataHex = CardIdTest.printData(reponseData);
                    System.out.println("command               : " + item);
                    System.out.println("response with data:   :" + dataHex);

                } else {
                    byte[] bytes = responseAPDU.getBytes();
                    String responseHex = CardIdTest.printData(bytes);
                    System.out.println("command               : " + item);
                    System.out.println("response without data :" + responseHex);
                }

            }
            card.disconnect(true); // reset

        } catch (CardException e) {

            e.printStackTrace();
        }

    }


    public static String printData(byte[] byteArray) {
        StringBuilder sb = new StringBuilder();

        for (byte b : byteArray) {
            sb.append(String.format(" %02x", b));
        }
        return sb.toString();

    }

}

修改

我有另一张卡Driver card,我可以使用以下APDU读取卡号

    String masterFile = "00 A4 04 0C 06 FF544143484F";
    String elementaryFile = "00 A4 02 0C 02 0520";
    String readBinary = "00 B0 00 01 10"; // B0 read binary; 01 offset 1; 10 decimal equal 16 bytes to read.

安装了cardpeek软件后,我已将此卡贴在读卡器中 - &gt;点击analayzer - &gt;点击行车记录仪,我就可以读取卡片数据,例如&#39; FF544143484F&#39; 0520&#39; IDS。当我将公司卡贴入读卡器时 - &gt; cardpeek Programm - &gt; analayer - &gt; (这里我没有点击正确的规范,因为我尝试了列表中的每一个,我只能读取ATR然后我得到6700错误)

0 个答案:

没有答案