我正在制作java应用程序,其主要功能是在java卡36k上编写数据,因此我需要有关java卡的资源,教程,诸如此类的东西。我没有制作java卡片应用程序的经验,所以请给我任何有用的资源。
我正在制作像RB 5.0这样的应用程序,如果你能给我这个应用程序的src代码会更好:)
智能卡规格:
- 全球平台卡规范(这是v 2.2.0.7,您的卡可能兼容较低版本)
- ISO/IEC 7816(通常需要第3部分和第4部分)
Java Card applet开发工具包(包括API规范+ RE和VM规范):
- Java卡开发工具包3.0.2(下载与您的卡兼容的版本)
与智能卡通信的Java应用程序库:
- javax。smartcardio(据我所知,它已从Java开发工具包的新版本中删除)
一个Java卡片小程序示例:(一个HelloWorld,从这里偷来的):
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);
}
}
与上述applet相关的Java程序(从这里偷来并修改后):
import java.util.List;
import javax.smartcardio.*;
public class Blog {
public static void main(String[] args) {
try {
// Display the list of terminals
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
// Use the first terminal
CardTerminal terminal = terminals.get(0);
// Connect with the card
Card card = terminal.connect("*");
System.out.println("card: " + card);
CardChannel channel = card.getBasicChannel();
// Send Select Applet command
byte[] aid = {(byte)0xA0, 0x00, 0x00, 0x00, 0x62, 0x03, 0x01, 0x0C, 0x06, 0x01}; //Replace your Applet AID instead of this AID here.
ResponseAPDU answer = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x04, 0x00, aid));
System.out.println("answer: " + answer.toString());
// Send test command
answer = channel.transmit(new CommandAPDU(0x00, 0x00, 0x00, 0x00));
System.out.println("answer: " + answer.toString());
byte r[] = answer.getData();
for (int i=0; i<r.length; i++)
System.out.print((char)r[i]);
System.out.println();
// Disconnect the card
card.disconnect(false);
} catch(Exception e) {
System.out.println("Ouch: " + e.toString());
}
}
}
必须将applet从.java
文件转换为.class
文件,从.class
文件转换为.cap
文件。JCDK包含了所需的工具。为了使这个过程更简单,您可以在中使用Eclipse- jcde插件Eclipse IDE(用于Java Card 2.2.2)或Netbeans IDE插件用于Java Card(默认包含在新版本中)
生成.CAP
文件后,需要将其上传并安装到卡上。为了达到这个目标,您可以使用文档完备的开源工具GlobalPlatformPro。
安装后,您可以使用上面提到的Java程序与applet通信,或者您可以使用另一个名为OpenSC-Tool的开源工具向卡发送APDU命令并接收响应。