0

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

java卡套件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);
}

}

4

1 回答 1

5

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

来自Runtime Environment Specification , Java Card Platform, Version 2.2.2(第 9.7 节):

可选扩展包

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

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

  • javacardx.apdu [...]
  • javacardx.biometry [...]
  • javacardx.crypto [...]
  • javacardx.external [...]
  • javacardx.framework [...]如果实施,此包必须包括所有包含的子包 - utilmathtlv.
于 2015-03-12T12:09:56.803 回答