使用smartcardio API的Java卡个性化脚本

时间:2018-01-25 19:55:45

标签: javacard apdu

您好我正在编写一个脚本,使用smartcardio API个性化Java卡。

以下是java代码

    TerminalFactory tf = TerminalFactory.getDefault();
    List<CardTerminal> terminals = tf.terminals().list();

    CardTerminal cardTerminal1 = (CardTerminal) terminals.get(0);
    Card connection1 = cardTerminal1.connect("T=0");
    CardChannel channel = connection1.getBasicChannel();

    byte[] apdu = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x07, (byte) 0xA0,(byte) 0x00, (byte) 0x00, (byte) 0x01,(byte) 0x51,(byte) 0x00,(byte) 0x00};
    String hex1 = DatatypeConverter.printHexBinary(apdu);
    System.out.println("Select Request : " + hex1 + "\n");

    ResponseAPDU respApdu = channel.transmit(new CommandAPDU(apdu));
    byte[] resp1 = respApdu.getBytes();
    hex1 = DatatypeConverter.printHexBinary(resp1);
    System.out.println("Select Response : " + hex1 + "\n");


     apdu = new byte[] { (byte) 0x80, (byte) 0xCA, (byte) 0x9F, (byte) 0x7F, (byte) 0x2A};
     hex1 = DatatypeConverter.printHexBinary(apdu);
     System.out.println("Get Request with CLA 80 : " + hex1 + "\n");


     respApdu = channel.transmit(new CommandAPDU(apdu));
     resp1 = respApdu.getBytes();
     hex1 = DatatypeConverter.printHexBinary(resp1);
     System.out.println("Get Response with CLA: " + hex1 + "\n");



    apdu = new byte[] { (byte) 0x00, (byte) 0xCA, (byte) 0x9F, (byte) 0x7F, (byte) 0x2A};
    hex1 = DatatypeConverter.printHexBinary(apdu);
    System.out.println("Get Request with CLA 00 : " + hex1 + "\n");


    respApdu = channel.transmit(new CommandAPDU(apdu));
    resp1 = respApdu.getBytes();
    hex1 = DatatypeConverter.printHexBinary(resp1);
    System.out.println("Get Response with CLA 00: " + hex1 + "\n");


     apdu = new byte[] { (byte) 0x80, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x08,(byte) 0xEC, (byte) 0xB9, (byte) 0x27, (byte) 0x11, (byte) 0xDF, (byte) 0x0F, (byte) 0x61, (byte) 0x79};

    hex1 = DatatypeConverter.printHexBinary(apdu);
    System.out.println("Initialize Request Command : " + hex1 + "\n");


    respApdu = channel.transmit(new CommandAPDU(apdu));
    resp1 = respApdu.getBytes();
    hex1 = DatatypeConverter.printHexBinary(resp1);
    System.out.println("Initialize Response : " + hex1 + "\n");

以下是输出

选择要求:00A4040007A0000001510000

选择响应:6F5B8407A0000001510000A550734A06072A864886FC6B01600C060A2A864886FC6B02020101630906072A864886FC6B03640B06092A864886FC6B040215650B06092B8510864864020103660C060A2B060104012A026E01029F6501FF9000

使用CLA 80获取请求:80CA9F7F2A

获得CLA回复:9F7F2A53430019492170676001E7702B05718231581144729111447291114472912A0D000000000000006D00

使用CLA 00:00CA9F7F2A获取请求

获取回应CLA 00:53430019492170676001E7702B05718231581144729111447291114472912A0D000000000000000000009000

初始化请求命令:8050000008ECB92711DF0F6179

初始化响应:6D00

如果我使用CLA 00发送命令,我会得到正确的响应90 00,否则卡片将返回6D 00。

如果有任何想法让我知道如何使用smartcardio API解决此问题?

1 个答案:

答案 0 :(得分:2)

这与智能卡无关,6D00表示卡无法识别您发送的命令。检查您的卡/小程序手册,了解命令APDU的正确编码。