2015-09-29 26 views
0

我想給的PIN,我智能卡與GPShell的-instParam選項。我發現了一些例子,但我沒有線索如何用給定的密碼初始化OwnerPIN對象。據我所知有是給我的小應用程序的安裝方法的LV編碼結構,但我怎麼解析。我嘗試了BERTLV對象,但是當安裝小程序時出現「條件不滿意」錯誤。 我有什麼:安裝參數JavaCard的

public static void install(byte[] bArray, short bOffset, byte bLength) 
      { 

       new MYPinCard(bArray, bOffset, bLength); 
      } 
    private MYPinCard(byte[] bArray, short bOffset, byte bLength) 
     { 
      m_pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE); 
      byte iLen = bArray[bOffset]; // aid length 
      short iOffset = (short) (bOffset+iLen+1); 
      iLen = bArray[iOffset]; // application privileges length 
      iOffset = (short) (iOffset+iLen+1); 
      iLen = bArray[iOffset]; // application specific parameters length 
      iOffset++; 

      try 
      { 
       m_pin.update(bArray, iOffset, iLen); 
      } 
      catch (PINException e) 
      { 
       ISOException.throwIt((short)0x6AAA); 
      } 
      testdata = new byte[iLen]; 

      Util.arrayCopy(bArray, bOffset, testdata, (short)0, iLen); 
      register(); 
     } 

private void getInstallParams(APDU apdu) 
    { 
     try 
     { 
      byte[] buffer = apdu.getBuffer(); 
      // inform the JCRE that the applet has data to return 
      short le = apdu.setOutgoing(); 
      // set the actual number of the outgoing data bytes 
      apdu.setOutgoingLength(((short)testdata.length)); 
      apdu.sendBytesLong(testdata, (short)0, (short)testdata.length); 

     } 
     catch (APDUException e) 
     { 
      ISOException.throwIt(SW_APDU_EXCEPTION); 
     } 
     catch (TransactionException e) 
     { 
      ISOException.throwIt(SW_TRANSACTION_EXCEPTION); 
     } 
     catch (ArrayIndexOutOfBoundsException e) 
     { 
      ISOException.throwIt(SW_AIOOB_EXCEPTION); 
     } 
     catch (NullPointerException e) 
     { 
      ISOException.throwIt(SW_NULLPOINTER_EXCEPTION); 
     } 
    } 

隨着getInstallParams()方法,我可以檢索的字節數。對於我的PIN是2字節的值,但我不知道如何處理該字節。

任何提示?

+0

的'Util.arrayCopy(bArray,bOffset,TESTDATA,(短)0,艾朗);'部分可能使用了錯誤的偏移 - 恕我直言'iOffset'應該在那裏(如果你想存儲的參數值)。 – vlp

回答

1

我一遍又一遍地使用該模板,它就可以工作(只要你有最多127個字節的參數):

public static void install(byte[] bArray, short bOffset, byte bLength) { 
    byte aidLength = bArray[bOffset]; 
    short controlLength = (short)(bArray[(short)(bOffset+1+aidLength)]&(short)0x00FF); 
    short dataLength = (short)(bArray[(short)(bOffset+1+aidLength+1+controlLength)]&(short)0x00FF); 
    new MyPinCard(bArray, (short) (bOffset+1+aidLength+1+controlLength+1), dataLength).register(bArray, (short) (bOffset + 1), aidLength); 
} 

private MyPinCard(byte[] bArray, short bOffset, short bLength) { 
    if(bLength!=(short)(2)) { 
     ISOException.throwIt(ISO7816.SW_WRONG_DATA); 
    } 
    // .... 
    m_pin = new OwnerPIN(PIN_TRY_LIMIT, (byte)2); 
    m_pin.update(bArray, bOffset, (byte)2); 
    // .... 
} 

注意&(short)0x00FF一部分正確處理負值字節。

注意,上面的代碼不檢查bLength參數的install()這是錯誤的,並將其固定:)

+0

嗯,這並不爲我工作....我比對PIN 2字節以上,但不會改變什麼,對不對? –

+0

GPShell有問題嗎?我安裝字符串是:安裝-file mypincard.cap -sdAID A000000018434D00 -nvCodeLimit 4096 -instParam 1234 –

+0

啊啊啊,當然,我需要給PARAMS爲十六進制:)對不起,混亂......現在它就像一個魅力:) –