2015-06-29 29 views
0

我想發送一個包含例如24個元素的隨機字節數組到我的JavaCard小程序,然後我的小程序應該使用特定方法更改該數組。例如,該方法XOR每個元素都帶有0x05,並在APDU響應中返回結果數組。在Java Card小程序安裝過程中接收6700狀態字錯誤

要瞄準上述目標,我寫了下面的程序至今:

>>> 80 00 00 00 18 11 22 33 44 55 66 77 88 99 10 20 30 40 50 60 70 80 90 b1 b2 b3 b4 b5 b6 b7 b8

和預期:

package keyGeneratorPackage; 

import javacard.framework.APDU; 
import javacard.framework.ISO7816; 
import javacard.framework.Applet; 
import javacard.framework.ISOException; 
import javacard.framework.JCSystem; 
import javacard.framework.Util; 

public class KeyGeneratorPackage extends Applet { 
    private static final byte HW_CLA = (byte) 0x80; 
    private static final byte HW_INS = (byte) 0x00; 

    public static void install(byte[] bArray, short bOffset, byte bLength) { 
     new keyGeneratorPackage.KeyGeneratorPackage().register(bArray, (short) (bOffset + 1), 
       bArray[bOffset]); 
    } 

    public void process(APDU apdu) { 
     if (selectingApplet()) { 
      return; 
     } 
     apdu.setIncomingAndReceive(); 
     byte[] buffer = apdu.getBuffer(); 
     byte CLA = (byte) (buffer[ISO7816.OFFSET_CLA] & 0xFF); 
     byte INS = (byte) (buffer[ISO7816.OFFSET_INS] & 0xFF); 
     short lc = (short) (buffer[ISO7816.OFFSET_LC] & (short)0x00FF); 
     byte[] Data = JCSystem.makeTransientByteArray(lc, JCSystem.CLEAR_ON_DESELECT); 

     if (CLA != HW_CLA) { 
      ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); 
     } 
     switch (INS) { 
     case HW_INS: { 
      // copying the apdu data into byte array Data 
      Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, Data, (short) 0, lc); 
      getKey(apdu, Data); 
     } 
     break; 
     default: 
      ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 
     } 
    } 

    private void getKey(APDU apdu, byte[] data) { 
     byte[] buffer = apdu.getBuffer(); 
     short length = (short) data.length; 
     //prepareing the key array of same length of Data 
     byte[] key = JCSystem.makeTransientByteArray(length, JCSystem.CLEAR_ON_DESELECT); 
     generateKey(data, key); 

     Util.arrayCopyNonAtomic(key, (short) 0, buffer, (short) 0, (short) length); 

     apdu.setOutgoingAndSend((short) 0, length); 
    } 

    private byte[] generateKey(byte[] Data, byte[] key) { 
     short i; 
     for (i = 0; i < Data.length; i++) { 
      key[i] = (byte) (Data[i]^(byte)0x05); 
     } 
     return key; 
    } 

} 

我必須編制並選擇我的小程序後發送以下APDU命令我的小程序必須返回的數據是:

<<< 14 27 36 41 50 ... bd 

我在安裝此Applet時遇到問題。

我無法將它安裝到我的Java卡上,但我確信我的小應用程序和我的卡之間的Java Card版本兼容性沒有問題。無論如何,我的程序是用Java Card Dev Kit 2.2.1編譯的。

值得注意的是,我創建了一個沒有任何附加代碼的默認Java Card項目,並且它已成功安裝在我的卡上。它也是由JavaCard開發工具包版本2.2.1編譯的。

我用globalPlatformPro安裝我的小程序,它給我0x6700錯誤的狀態字。

更新1:

我進入安裝帶有-v參數-d命令。 OutPut是:

E:\javacard\GlobalPlatformPro>gp -install E:\newPack.cap -v -d 
# Detected readers from SunPCSC 
[ ] Duali DE-ABCM Contactless Reader 0 
[ ] Duali DE-ABCM Sam1 Reader 0 
[*] Duali DE-ABCM Sam2 Reader 0 
[ ] JAVACOS Virtual Contact Reader 0 
[ ] JAVACOS Virtual Contactless Reader 1 
SCardConnect("Duali DE-ABCM Sam2 Reader 0", T=*) -> T=0, 3B6B000080653140DC48428 
3009000 
SCardBeginTransaction("Duali DE-ABCM Sam2 Reader 0") 
Reader: Duali DE-ABCM Sam2 Reader 0 
ATR: 3B6B000080653140DC484283009000 
More information about your card: 
    http://smartcard-atr.appspot.com/parse?ATR=3B6B000080653140DC484283009000 

A>> T=0 (4+0000) 00A40400 00 
A<< (0027+2) (73ms) 6F198408A000000003000000A50D9F6E064842928832319F6501FF 9000 
Auto-detected ISD AID: A000000003000000 
# ... 
# Authentication Process Censored. 
# ... 
CAP file (v2.1) generated on Mon Jun 29 10:11:23 IRDT 2015 
By Sun Microsystems Inc. converter 1.3 with JDK 1.7.0_09 (Oracle Corporation) 
Package: newPack v1.2 with AID 1020304050 
Applet: newApplet with AID 10203040500000 
Import: A0000000620101 v1.2 
A>> T=0 (4+0010) 84F28000 0A 4F0031993E2681C862DD 00 
A<< (0011+2) (599ms) 08A000000003000000019E 9000 
A>> T=0 (4+0010) 84F24000 0A 4F00EFCEFA0D825EAC3B 00 
A<< (0011+2) (91ms) 08AABBCCDDEEFF00000700 9000 
A>> T=0 (4+0010) 84F22000 0A 4F0050316231A15388BE 00 
A<< (0143+2) (277ms) 08D156000027100106010008D156000027100101010006A000000151000 
10007A0000000030000010008D156000027100102010007A0000000620201010007A000000062010 
2010008A000000062010101010007A0000000620101010007A0000000620002010007A0000000620 
003010007A0000000620001010008D156000027100108010006AABBCCDDEEFF0100 9000 
A>> T=0 (4+0010) 84F21000 0A 4F00358E1689D8208F09 00 
A<< (0176+2) (331ms) 08D15600002710010601000008D15600002710010101000006A00000015 
10001000007A000000003000001000008D15600002710010201000007A000000062020101000007A 
000000062010201000008A00000006201010101000007A000000062010101000007A000000062000 
201000007A000000062000301000007A000000062000101000008D15600002710010801000109D15 
60000271001080106AABBCCDDEEFF01000108AABBCCDDEEFF0000 9000 
A>> T=0 (4+0026) 84E60200 1A 05102030405008A0000000030000000000005DC20F51A0D4CA2 
9 
A<< (0001+2) (474ms) 9000 
A>> T=0 (4+0255) 84E80000 FF C482018E01000FDECAFFED010204020105102030405002001F0 
00F001F000B000B003A000C00CA000A00150000008700000000000001010004000B01020107A0000 
00062010103000B010710203040500000000806000C00800300FF0007010000001C0700CA0001101 
88C00007A05308F00013D8C0002181D0441181D258B00037A0525188B000460037A198B00053B198 
B00062D1A03251100FF535B321A04251100FF535B29041A07251100FF5329051605058D000728061 
F10806A08116E008D0008160473001D0000000000091A0815060316058D00093B181915068C000A7 
008116D008D00087A0533198B00062E1A9229041604AA59A4DD02FCF125 
A<< (0000+2) (792ms) 6700 
pro.javacard.gp.GPException: LOAD failed SW: 6700 
     at pro.javacard.gp.GlobalPlatform.check(GlobalPlatform.java:1092) 
     at pro.javacard.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:728) 
     at pro.javacard.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:686) 
     at pro.javacard.gp.GPTool.main(GPTool.java:453) 

我的小程序有什麼問題嗎?什麼是問題?

+1

請在安裝命令中使用'-d -v'參數時添加安裝過程的輸出。 I.e輸出'gp.exe -install E:\ keyGeneratorPackage.cap -v -d' – Abraham

+0

您是否嘗試過使用相同的工具,讀取器和卡加載另一個.cap文件?有些閱讀器和卡片不喜歡數據部分長度爲255的APDU。如果可能的話,您可以爲小應用程序安裝設置較低的塊大小。 – vojta

+0

我通過gpj成功安裝了我的小程序。但是當我發送命令發送數據並通過Opensc工具接收到更改的數據時,它會返回無效的數據,這意味着命令不正確。什麼是問題?我會用我在gpj平臺上收到的輸出更新我的問題。 –

回答

0

我可以在我的智能卡上成功安裝我的小程序,但是通過gpj平臺。 在GPJ平臺上安裝的輸出是:

Microsoft Windows [Version 6.1.7601] 
Copyright (c) 2009 Microsoft Corporation. All rights reserved. 

C:\Users\Ehsan>java -jar E:\javacard\gpj\gpj.jar -load E:\keyGeneratorPackage.ca 
p -install 
Found terminals: [PC/SC terminal Duali DE-ABCM Contactless Reader 0, PC/SC termi 
nal Duali DE-ABCM Sam1 Reader 0, PC/SC terminal Duali DE-ABCM Sam2 Reader 0, PC/ 
SC terminal JAVACOS Virtual Contact Reader 0, PC/SC terminal JAVACOS Virtual Con 
tactless Reader 1] 
javax.smartcardio.CardNotPresentException: No card present 
     at sun.security.smartcardio.TerminalImpl.connect(Unknown Source) 
     at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S 
ource) 
Caused by: sun.security.smartcardio.PCSCException: SCARD_W_REMOVED_CARD 
     at sun.security.smartcardio.PCSC.SCardConnect(Native Method) 
     at sun.security.smartcardio.CardImpl.<init>(Unknown Source) 
     ... 2 more 
Found card in terminal: Duali DE-ABCM Contactless Reader 0 
java.lang.NullPointerException 
     at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S 
ource) 
javax.smartcardio.CardNotPresentException: No card present 
     at sun.security.smartcardio.TerminalImpl.connect(Unknown Source) 
     at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S 
ource) 
Caused by: sun.security.smartcardio.PCSCException: SCARD_W_REMOVED_CARD 
     at sun.security.smartcardio.PCSC.SCardConnect(Native Method) 
     at sun.security.smartcardio.CardImpl.<init>(Unknown Source) 
     ... 2 more 
Found card in terminal: Duali DE-ABCM Sam1 Reader 0 
java.lang.NullPointerException 
     at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S 
ource) 
Found card in terminal: Duali DE-ABCM Sam2 Reader 0 
ATR: 3B 6B 00 00 80 65 31 40 DC 48 42 83 00 90 00 
DEBUG: Command APDU: 00 A4 04 00 07 A0 00 00 01 51 00 00 
DEBUG: Response APDU: 6A 82 
Failed to select Security Domain GP211 A0 00 00 01 51 00 00 , SW: 6A 82 
DEBUG: Command APDU: 00 A4 04 00 08 A0 00 00 00 18 43 4D 00 
DEBUG: Response APDU: 6A 82 
Failed to select Security Domain GemaltoXpressPro A0 00 00 00 18 43 4D 00 , SW: 
6A 82 
DEBUG: Command APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00 
DEBUG: Response APDU: 6F 19 84 08 A0 00 00 00 03 00 00 00 A5 0D 9F 6E 06 48 42 9 
2 88 32 31 9F 65 01 FF 90 00 
Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00 
DEBUG: Command APDU: 80 50 00 00 08 BF A2 14 ED 0F E0 4A E0 
DEBUG: Response APDU: 00 00 1E 60 31 80 00 01 77 7B 01 02 00 CD E9 F9 F5 18 BC A 
3 C9 F1 59 25 9A 38 DD 3C 90 00 
DEBUG: Command APDU: 84 82 00 00 10 BD 78 CC 1D 5B 7F E5 46 D4 6C 02 D4 0D 32 4 
6 E3 
DEBUG: Response APDU: 90 00 
DEBUG: Command APDU: 84 82 00 00 08 BD 78 CC 1D 5B 7F E5 46 
DEBUG: Response APDU: 90 00 
DEBUG: packagePath: keyGeneratorPackage/javacard/ 
DEBUG: package: keyGeneratorPackage 
DEBUG: package AID: 1C 2C 3C 4C 5C 
DEBUG: applet AIDs: [1C 2C 3C 4C 5C 00 ] 
DEBUG: Command APDU: 80 E6 02 00 12 05 1C 2C 3C 4C 5C 08 A0 00 00 00 03 00 00 0 
0 00 00 00 
DEBUG: Response APDU: 00 90 00 
DEBUG: Command APDU: 80 E6 02 00 12 05 1C 2C 3C 4C 5C 08 A0 00 00 00 03 00 00 0 
0 00 00 00 
DEBUG: Response APDU: 00 90 00 
DEBUG: Command APDU: 80 E8 00 00 FF C4 82 01 86 01 00 0F DE CA FF ED 01 02 04 0 
1 01 05 1C 2C 3C 4C 5C 02 00 1F 00 0F 00 1F 00 0A 00 0B 00 3A 00 0C 00 C3 00 0A 
00 15 00 00 00 87 00 00 00 00 00 00 01 01 00 04 00 0B 01 02 01 07 A0 00 00 00 62 
01 01 03 00 0A 01 06 1C 2C 3C 4C 5C 00 00 0C 06 00 0C 00 80 03 00 FF 00 07 01 0 
0 00 00 15 07 00 C3 00 01 10 18 8C 00 00 18 8B 00 01 7A 01 30 8F 00 02 8C 00 03 
7A 05 25 18 8B 00 04 60 03 7A 19 8B 00 05 3B 19 8B 00 06 2D 1A 03 25 11 00 FF 53 
5B 32 1A 04 25 11 00 FF 53 5B 29 04 1A 07 25 11 00 FF 53 29 05 16 05 05 8D 00 0 
7 28 06 1F 10 80 6A 08 11 6E 00 8D 00 08 16 04 73 00 1D 00 00 00 00 00 09 1A 08 
15 06 03 16 05 8D 00 09 3B 18 19 15 06 8C 00 0A 70 08 11 6D 00 8D 00 08 7A 05 33 
19 8B 00 06 2E 1A 92 29 04 16 04 05 8D 00 07 28 05 18 1A 15 05 8C 00 0B 3B 15 0 
5 
DEBUG: Response APDU: 90 00 
DEBUG: Command APDU: 80 E8 00 00 FF C4 82 01 86 01 00 0F DE CA FF ED 01 02 04 0 
1 01 05 1C 2C 3C 4C 5C 02 00 1F 00 0F 00 1F 00 0A 00 0B 00 3A 00 0C 00 C3 00 0A 
00 15 00 00 00 87 00 00 00 00 00 00 01 01 00 04 00 0B 01 02 01 07 A0 00 00 00 62 
01 01 03 00 0A 01 06 1C 2C 3C 4C 5C 00 00 0C 06 00 0C 00 80 03 00 FF 00 07 01 0 
0 00 00 15 07 00 C3 00 01 10 18 8C 00 00 18 8B 00 01 7A 01 30 8F 00 02 8C 00 03 
7A 05 25 18 8B 00 04 60 03 7A 19 8B 00 05 3B 19 8B 00 06 2D 1A 03 25 11 00 FF 53 
5B 32 1A 04 25 11 00 FF 53 5B 29 04 1A 07 25 11 00 FF 53 29 05 16 05 05 8D 00 0 
7 28 06 1F 10 80 6A 08 11 6E 00 8D 00 08 16 04 73 00 1D 00 00 00 00 00 09 1A 08 
15 06 03 16 05 8D 00 09 3B 18 19 15 06 8C 00 0A 70 08 11 6D 00 8D 00 08 7A 05 33 
19 8B 00 06 2E 1A 92 29 04 16 04 05 8D 00 07 28 05 18 1A 15 05 8C 00 0B 3B 15 0 
5 
DEBUG: Response APDU: 90 00 
DEBUG: Command APDU: 80 E8 80 01 8B 03 1B 03 16 04 8D 00 0C 3B 19 03 16 04 8B 0 
0 0D 7A 04 31 03 32 70 0D 1A 1F 19 1F 25 08 57 38 59 03 01 1F 19 92 6C F2 1A 77 
08 00 0A 00 00 00 00 00 00 00 00 00 00 05 00 3A 00 0E 06 80 03 00 03 80 03 01 01 
00 00 00 06 00 00 01 03 80 03 03 03 80 0A 06 03 80 0A 01 06 80 08 0D 06 80 07 0 
1 06 80 10 01 06 00 00 7D 06 00 00 AB 06 80 10 02 03 80 0A 08 09 00 15 00 00 00 
11 05 04 06 03 07 07 05 23 0D 15 08 08 07 0B 09 0B 08 
DEBUG: Response APDU: 00 90 00 
DEBUG: Command APDU: 80 E8 80 01 8B 03 1B 03 16 04 8D 00 0C 3B 19 03 16 04 8B 0 
0 0D 7A 04 31 03 32 70 0D 1A 1F 19 1F 25 08 57 38 59 03 01 1F 19 92 6C F2 1A 77 
08 00 0A 00 00 00 00 00 00 00 00 00 00 05 00 3A 00 0E 06 80 03 00 03 80 03 01 01 
00 00 00 06 00 00 01 03 80 03 03 03 80 0A 06 03 80 0A 01 06 80 08 0D 06 80 07 0 
1 06 80 10 01 06 00 00 7D 06 00 00 AB 06 80 10 02 03 80 0A 08 09 00 15 00 00 00 
11 05 04 06 03 07 07 05 23 0D 15 08 08 07 0B 09 0B 08 
DEBUG: Response APDU: 00 90 00 
DEBUG: Command APDU: 80 E6 0C 00 1A 05 1C 2C 3C 4C 5C 06 1C 2C 3C 4C 5C 00 06 1 
C 2C 3C 4C 5C 00 01 00 02 C9 00 00 
DEBUG: Response APDU: 00 90 00 
DEBUG: Command APDU: 80 E6 0C 00 1A 05 1C 2C 3C 4C 5C 06 1C 2C 3C 4C 5C 00 06 1 
C 2C 3C 4C 5C 00 01 00 02 C9 00 00 
DEBUG: Response APDU: 00 90 00 
javax.smartcardio.CardNotPresentException: No card present 
     at sun.security.smartcardio.TerminalImpl.connect(Unknown Source) 
     at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S 
ource) 
Caused by: sun.security.smartcardio.PCSCException: SCARD_W_REMOVED_CARD 
     at sun.security.smartcardio.PCSC.SCardConnect(Native Method) 
     at sun.security.smartcardio.CardImpl.<init>(Unknown Source) 
     ... 2 more 
Found card in terminal: JAVACOS Virtual Contact Reader 0 
java.lang.NullPointerException 
     at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S 
ource) 
javax.smartcardio.CardNotPresentException: No card present 
     at sun.security.smartcardio.TerminalImpl.connect(Unknown Source) 
     at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S 
ource) 
Caused by: sun.security.smartcardio.PCSCException: SCARD_W_REMOVED_CARD 
     at sun.security.smartcardio.PCSC.SCardConnect(Native Method) 
     at sun.security.smartcardio.CardImpl.<init>(Unknown Source) 
     ... 2 more 
Found card in terminal: JAVACOS Virtual Contactless Reader 1 
java.lang.NullPointerException 
     at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S 
ource) 

C:\Users\Ehsan> 

我無法通過globalPlatformPro.I智能卡上安裝我的小程序不知道的原因,在此平臺上安裝命令的輸出反正是:

E:\javacard\GlobalPlatformPro>gp -install E:\keyGeneratorPackage.cap 

pro.javacard.gp.GPException: LOAD failed SW: 6700 
     at pro.javacard.gp.GlobalPlatform.check(GlobalPlatform.java:1092) 
     at pro.javacard.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:728) 
     at pro.javacard.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:686) 
     at pro.javacard.gp.GPTool.main(GPTool.java:453) 

E:\javacard\GlobalPlatformPro> 

這是我的卡上的最後四個AID和前四個AID是我的應用程序包和應用程序小程序通過gpj安裝的小程序列表。

E:\javacard\GlobalPlatformPro> 
E:\javacard\GlobalPlatformPro>gp -l 
AID: A000000003000000 (|........|) 
    ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected, 
CVM (PIN) management 

AID: AABBCCDDEEFF0000 (|........|) 
    App SELECTABLE: (none) 

AID: 010203040506070809AABB (|...........|) 
    App SELECTABLE: (none) 

AID: A9A8A7A6A5A400 (|.......|) 
    App SELECTABLE: (none) 

AID: 1C2C3C4C5C00 (|.,<L\.|) 
    App SELECTABLE: (none) 

AID: D156000027100106 (|.V..'...|) 
    ExM LOADED: (none) 

AID: D156000027100101 (|.V..'...|) 
    ExM LOADED: (none) 

AID: A00000015100 (|....Q.|) 
    ExM LOADED: (none) 

AID: A0000000030000 (|.......|) 
    ExM LOADED: (none) 

AID: D156000027100102 (|.V..'...|) 
    ExM LOADED: (none) 

AID: A0000000620201 (|....b..|) 
    ExM LOADED: (none) 

AID: A0000000620102 (|....b..|) 
    ExM LOADED: (none) 

AID: A000000062010101 (|....b...|) 
    ExM LOADED: (none) 

AID: A0000000620101 (|....b..|) 
    ExM LOADED: (none) 

AID: A0000000620002 (|....b..|) 
    ExM LOADED: (none) 

AID: A0000000620003 (|....b..|) 
    ExM LOADED: (none) 

AID: A0000000620001 (|....b..|) 
    ExM LOADED: (none) 

AID: D156000027100108 (|.V..'...|) 
    ExM LOADED: (none) 
    D15600002710010801 (|.V..'....|) 

AID: AABBCCDDEEFF (|......|) 
    ExM LOADED: (none) 
    AABBCCDDEEFF0000 (|........|) 

AID: 010203040506070809 (|.........|) 
    ExM LOADED: (none) 
    010203040506070809AABB (|...........|) 

AID: A9A8A7A6A5A4 (|......|) 
    ExM LOADED: (none) 
    A9A8A7A6A5A400 (|.......|) 

AID: 1C2C3C4C5C (|.,<L\|) 
    ExM LOADED: (none) 
    1C2C3C4C5C00 (|.,<L\.|) 


E:\javacard\GlobalPlatformPro> 

這是我最後的applet代碼:

package keyGeneratorPackage; 

import javacard.framework.APDU; 
import javacard.framework.Applet; 
import javacard.framework.ISO7816; 
import javacard.framework.ISOException; 
import javacard.framework.JCSystem; 
import javacard.framework.Util; 

public class keyGeneratorApplet extends Applet { 
    /* constants declaration */ 
    // code of CLA byte in the command APDU header 

    // codes of INS byte in the command APDU header 
    private static final byte HW_CLA = (byte) 0x80; 
    private static final byte HW_INS = (byte) 0x00; 
    private keyGeneratorApplet() { 
     register(); 
    } 

    public static void install(byte bArray[], short bOffset, byte bLength) 
      throws ISOException { 
     new keyGeneratorApplet(); 
    } 


    public void process(APDU apdu) { 
     if (selectingApplet()) { 
      return; 
     } 
     apdu.setIncomingAndReceive(); 
     byte[] buffer = apdu.getBuffer(); 
     byte CLA = (byte) (buffer[ISO7816.OFFSET_CLA] & 0xFF); 
     byte INS = (byte) (buffer[ISO7816.OFFSET_INS] & 0xFF); 
     short lc = (short) (buffer[ISO7816.OFFSET_LC] & (short)0x00FF); 
//  byte[] Data = new byte[(byte) (buffer[ISO7816.OFFSET_LC] & 0xFF)]; 
     byte[] Data = JCSystem.makeTransientByteArray(lc, JCSystem.CLEAR_ON_DESELECT); 

     if (CLA != HW_CLA) { 
      ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); 
     } 
     switch (INS) { 
     case HW_INS: { 
      // copying the apdu data into byte array Data 
      Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, Data, (short) 0, lc); 
      getKey(apdu, Data); 
     } 
     // you forget to put a break here! 
     break; 
     default: 
      // good practice: If you don't know the INStruction, say so: 
      ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 
     } 
    } 

    private void getKey(APDU apdu, byte[] data) { 
     byte[] buffer = apdu.getBuffer(); 
     short length = (short) data.length; 
     //prepareing the key array of same length of Data 
     byte[] key = JCSystem.makeTransientByteArray(length, JCSystem.CLEAR_ON_DESELECT); 
//  byte[] generatedKey = generateKey(data, key); 
     // no need another array generatedKey, as we are passing key as parameter 
     generateKey(data, key); 
//  length = (short) generatedKey.length; 

     Util.arrayCopyNonAtomic(key, (short) 0, buffer, (short) 0, (short) length); 

     apdu.setOutgoingAndSend((short) 0, length); 
    } 

    // ..................................... 
    private byte[] generateKey(byte[] Data, byte[] key) { 
     short i; 
     for (i = 0; i < Data.length; i++) { 
      // i've no idea why you use 0x05 here, 
      // in the question you mentioned 0x9D 
      key[i] = (byte) (Data[i]^(byte)0x05); 
     } 
     return key; 
    } 
} 

以及發送我的命令到我的小應用程序被安裝在卡上,我從OpenSc工具使用。輸入和輸出在這裏:

E:\javacard\opensc-tools\OpenSC-master>opensc-tool.exe -r"Duali DE-ABCM Sam2 Rea 
der 0" -s 00a40400061c2c3c4c5c00 -s 80000000181122334455667788991020304050607080 
90B1B2B3B4B5B6B7 
Sending: 00 A4 04 00 06 1C 2C 3C 4C 5C 00 
Received (SW1=0x90, SW2=0x00) 
Sending: 80 00 00 00 18 11 22 33 44 55 66 77 88 99 10 20 30 40 50 60 70 80 90 B1 
B2 B3 B4 B5 B6 B7 
Received (SW1=0x90, SW2=0x00): 
14 27 36 41 50 63 72 8D 9C 15 25 35 45 55 65 75 .'6APcr...%5EUeu 
85 95 B4 B7 B6 B1 B0 B3       ........ 

E:\javacard\opensc-tools\OpenSC-master> 
+1

這似乎不是一個答案......你說你不知道發生了什麼事情,globalPlatformPro的問題仍然沒有解決。也許你不應該接受你自己的答案,因爲人們會停止看這個問題...... – vojta