[英]How to try using Native Methods in Java card applets?
这是一个用于Javacard的简单Hello World小程序:
package helloWorldPackage;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;
public class HelloWorldApplet extends Applet {
private static final byte[] helloWorld = {(byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o',(byte)' ',(byte)'W',(byte)'o',(byte)'r',(byte)'l',(byte)'d',};
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 HelloWorldApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
byte[] buffer = apdu.getBuffer();
byte CLA = (byte) (buffer[ISO7816.OFFSET_CLA] & 0xFF);
byte INS = (byte) (buffer[ISO7816.OFFSET_INS] & 0xFF);
if (CLA != HW_CLA)
{
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
switch ( INS ) {
case HW_INS:
getHelloWorld( apdu );
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
private void getHelloWorld( APDU apdu)
{
byte[] buffer = apdu.getBuffer();
short length = (short) helloWorld.length;
Util.arrayCopyNonAtomic(helloWorld, (short)0, buffer, (short)0, (short) length);
apdu.setOutgoingAndSend((short)0, length);
}
}
问题是“ java卡中的本地方法是什么意思?”
在智能卡的安全目标中,写有“防止在应用程序中使用本机方法”。 问题是“如何针对特定卡进行测试?” 换句话说,我希望您修改上面的代码并向其中添加一些本机方法,然后让我检查是否可以将其转换为.cap文件并将其上传到我的卡上。
更新:
正如亲爱的TonyK在第一句话中所说,大概我的开发环境不会编译这样的东西,因此有两个问题:
本机方法是可以用Java程序调用的用另一种编程语言(即不是用Java)编写的方法。 对于智能卡,本机方法通常用C代码或机器代码编写,并直接在基础智能卡处理器上执行(而Java Card应用程序在Java Card虚拟机内部执行)。
关于Java Card语言以及使用CAP文件执行加载到Java Card的applet的执行,您实际上不必担心本机方法:
native
关键字,因此您不能声明本机方法(请参阅第2-4页的虚拟机规范Java Card Platform,版本2.2.2 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.