首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安装参数JavaCard

安装参数JavaCard
EN

Stack Overflow用户
提问于 2015-09-29 09:26:22
回答 1查看 1K关注 0票数 0

我正在尝试给我的智能卡的密码与-instParam选项在GPShell。我找到了一些例子,但我不知道如何用给定的PIN初始化OwnerPIN对象。AFAIK有一个LV编码结构,给出了我的applet的安装方法,但是我如何解析它。我尝试了BERTLV对象,但是在安装applet时我得到了一个“不满足的条件”错误。我所拥有的:

代码语言:javascript
复制
  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字节值,但我不知道如何处理这些字节。

有什么暗示吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-29 09:57:05

我一遍又一遍地使用这个模板,它只是起作用(只要你有最多127个字节的参数):

代码语言:javascript
复制
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部件,它正确地处理带有负值的字节。

请注意,上面的代码没有检查bLengthinstall()参数,这是错误的,应该修复:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32840420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档