使用javacardx.framework.math.BigNumber时,applet无法安装

时间:2015-03-12 11:27:47

标签: applet smartcard javacard jcop

我在javacard applet中声明BigNumber数据类型时遇到了问题。如果我只是评论声明,applet正确加载到模拟器中。准确的问题是在加载import.cap文件时 (jcshell:错误代码:6a80(错误的数据))

java card kit 2.2.2使用

  import javacard.framework.APDU;
  import javacard.framework.Applet;
  import javacard.framework.ISO7816;
  import javacard.framework.ISOException;
  import javacard.framework.JCSystem;
  import javacardx.framework.math.BigNumber;

 public class LargeBal extends Applet {

 // CLA byte
public static final byte BANK_CLA = (byte) 0x80;

// INS byte
public static final byte INS_GET_BALANCE = 0X02;
public static final byte INS_CREDIT = 0X04;
public static final byte INS_DEBIT = 0X06;

/**
 * SW bytes for Arithmetic exception
 */
final static short INVALID_NUMBER_FORMAT = 0x6308;

/**
 * Initial account balance
 */
final static byte[] INITIAL_ACCOUNT_BALANCE = { (byte) 0x01, (byte) 0x00,
        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };

// Amount of money in user's account

private BigNumber accountBalance;

// Big number for temporary calculation
BigNumber tempBigNum;

// temporary buffer used as scratch space

byte[] scratchSpace;

private LargeBal() {

     accountBalance = new BigNumber((byte) 8);

    // initialize account balance to 100,000.00
     accountBalance.init(INITIAL_ACCOUNT_BALANCE, (byte) 0,
     (byte) INITIAL_ACCOUNT_BALANCE.length, BigNumber.FORMAT_BCD);

    // initialize the temporary big number
     tempBigNum = new BigNumber(BigNumber.getMaxBytesSupported());

    // initialize the scratchSpace
    scratchSpace = JCSystem.makeTransientByteArray((short) 10,
            JCSystem.CLEAR_ON_DESELECT);
    register();
}

public static void install(byte[] bArray, short bOffset, byte bLength) {
    // GP-compliant JavaCard applet registration
    new LargeBal();
}

public void process(APDU apdu) {
    // Good practice: Return 9000 on SELECT
    if (selectingApplet()) {
        return;
    }

    byte[] buf = apdu.getBuffer();
    switch (buf[ISO7816.OFFSET_INS]) {
    case INS_GET_BALANCE:
         getBalance(apdu, buf);
        break;
    case INS_CREDIT:

        break;
    case INS_DEBIT:

        break;
    default:
        // good practice: If you don't know the INStruction, say so:
        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }
}

private void getBalance(APDU apdu, byte[] buffer) {

    if (buffer[ISO7816.OFFSET_P1] == BigNumber.FORMAT_BCD) {
        accountBalance.toBytes(buffer, (short) 0, (short) 8,
                BigNumber.FORMAT_BCD);
    } else if (buffer[ISO7816.OFFSET_P1] == BigNumber.FORMAT_HEX) {
        accountBalance.toBytes(buffer, (short) 0, (short) 8,
                BigNumber.FORMAT_HEX);
    } else
        ISOException.throwIt(INVALID_NUMBER_FORMAT);

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

}

1 个答案:

答案 0 :(得分:5)

javacardx.framework.math可选包。因此,并非所有的卡/模拟器都能实现这一点。在您的情况下,该卡似乎没有实现javacardx.framework.math.BigNumber。因此,它拒绝加载/安装applet。

来自运行时环境规范,Java Card Platform,版本2.2.2(第9.7节):

  

可选扩展包

     

Java Card技术中的一些API包被指定为扩展名   包可以选择性地支持包。但是,如果支持,   包中的所有类及其子包必须由   平台并驻留在卡上。

     

以下是可选的Java Card技术扩展包:

     
      
  • javacardx.apdu [...]
  •   
  • javacardx.biometry [...]
  •   
  • javacardx.crypto [...]
  •   
  • javacardx.external [...]
  •   
  • javacardx.framework [...] 如果已实施,此套餐必须包含所有包含的子包 - utilmathtlv
  •