简体   繁体   English

解码/解密 APDU 响应 Java 卡

[英]Decode/Decrypt APDU responses Java Card

I use smartcardio library to communicate with smart card by Java.我使用 smartcardio 库通过 Java 与智能卡进行通信。 I get responses from card then I want to decode the response to text and it's kinda complicated.我收到卡片的回复,然后我想解码对文本的回复,这有点复杂。

Example :例子 :

  1. I select the file on the card.我选择卡上的文件。
  2. Get Binary response from the file.从文件中获取二进制响应。
  3. Read response to console.读取对控制台的响应。

The response looks :响应如下:

ResponseAPDU: 145 bytes, SW=9000

Hex : 13E013A801C800001AB4138E03931BC6142B1C3214371C5114531C5B04FA24FB0026001252AE42800554003E200005621D670012002252AF9400055502C518001083188700B2195501C91BEB04601C6904FC1D660022003652B0E580055601AF180010561875108F189200941B9213CA1BD613D81BDB143E1C4314481C4A144F04511CA315261D2D656B0036001A529000

Binary:  10011111000000001001110101000000000011100100000000000000000000001101010110100000100111000111000000011100100110001101111000110000101000010101100011100001100100001010000110111000111000101000100010100010100110001110001011011000001001111101000100100111110110000000000100110000000000001001001010010101011100100001010000000000001010101010000000000001111100010000000000000000001010110001000011101011001110000000000010010000000000010001001010010101011111001010000000000000001010101010100000010110001010001100000000000000100001000001100011000100001110000000010110010000110010101010100000001110010010001101111101011000001000110000000011100011010010000010011111100000111010110011000000000001000100000000000110110010100101011000011100101100000000000010101010110000000011010111100011000000000000001000001010110000110000111010100010000100011110001100010010010000000001001010000011011100100100001001111001010000110111101011000010011110110000001101111011011000101000011111000011100010000110001010001001000000111000100101000010100010011110000010001010001000111001010001100010101001001100001110100101101011001010110101100000000001101100000000000011010010100101001000000000000

After execute : 
System.out.println("Response : " + new String(r.getData()));

new String(r.getBytes(), 0, r.getBytes().length, "UTF8")); --> give me almost the same result.

I get : 
���  ����+27QS[�$� & R�B�T >  bg  "R�� U� �� �U��`i�f " 6R���V� Vu�� ������>CHJOQ�&-ek 6 R� 

Is there different way to decode responses from the card to text?是否有不同的方式来解码从卡片到文本的响应? It's great that I get responses from card, but it's useless if I even don't know what I get.收到卡片的回复很棒,但如果我什至不知道自己收到了什么,那也没有用。 Most of solutions I found about decoding apdu responses are simple like my above, but this solution isn't enough.我发现的大多数关于解码 apdu 响应的解决方案都像上面一样简单,但这个解决方案还不够。

Also tried decode the response by checking all charsets:还尝试通过检查所有字符集来解码响应:

        SortedMap<String,Charset> charsets = Charset.availableCharsets();
        Iterator i = charsets.entrySet().iterator();

        while (i.hasNext())
        {
            Map.Entry m = (Map.Entry)i.next();
            String key = (String)m.getKey();

            System.out.println("Response charset " + key + " : " + new String(r.getBytes(), 0, r.getBytes().length, key));
        }

Read Binary may easily (ie more often than not) return non-text data. Read Binary可能很容易(即经常)返回非文本数据。 This depends on the specification of the application.这取决于应用程序的规范。 Without additional information, what specification the card conforms to, and which file it is, our guess is not better than yours.没有额外的信息,卡符合什么规格,它是哪个文件,我们的猜测并不比你的好。 Note, that often a structured data-format called BER-TLV is used by smartcards.请注意,智能卡通常使用称为 BER-TLV 的结构化数据格式。 As a start, try to get hold of ISO 7816, part 4 for an introduction.首先,尝试掌握 ISO 7816,第 4 部分的介绍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM