Getting Started with Javacard – compiling & installing the Helloworld Sample

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

Software I am using:


  • IBM JCOP31 – Javacard 2.2
  • Omnikey 3121 Smartcard Reader/Writer

1.Open a command prompt and navigate to \java_card_kit-2_2_2\samples\src

2.Prior to using the java compiler and CAP conversion tool, you will need to setup the following environmental variables.  I use a little batch script to setup mine, below;

set JAVA_HOME=C:\Progra~1\Java\jre7
set JC_HOME=C:\dev\java_card_kit-2_2_2-windows\java_card_kit-2_2_2\java_card_kit-2_2_2-rr-bin-windows-do
set JC_EXPORTS=%JC_HOME%\api_export_files
set CLASSPATH=.;%JC_HOME%\lib\javacardframework.jar;%JC_HOME%\lib\api.jar;%JC_HOME%\lib\installer.jar;
set PATH=%JAVA_HOME%\bin;%JC_HOME%\bin;%PATH%;

Avoid using spaces and quotes within paths.

3. Compile to Java Byte Code

javac -source 1.2 -target 1.2 %JC_HOME%\samples\src\com\sun\javacard\samples\HelloWorld\

Will result in the creation of HelloWorld.class and HelloWorld.opt (converter options file)

4.  Modify the options file with the full path to the JC_EXPORTS directory;

-exportpath C:\dev\java_card_kit-2_2_2-windows\java_card_kit-2_2_2\java_card_kit-2_2_2-rr-bin-windows-do\api_export_files
-applet  0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x1:0x1 com.sun.javacard.samples.HelloWorld.HelloWorld
0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x1 1.0

Then convert the javabyte code into a javacard CAP package.

> converter -config C:\java_card_kit-2_2_2\samples\src\com\sun\javacard\samples\HelloWorld\HelloWorld.opt

5. Navigate command prompt to \GPShell-1.4.4

GPShell using
Put the following in the text file:

select -AID a000000003000000
open_sc -security 0 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f
delete -AID A00000006203010C0101
delete -AID A00000006203010C01
install_for_load -pkgAID A00000006203010C01
load -file C:\java_card_kit-2_2_1\samples\src\com\sun\javacard\samples\HelloWorld\javacard\HelloWorld.cap
install_for_install -priv 4 -AID A00000006203010C0101 -pkgAID A00000006203010C01 -instAID A00000006203010C0101FF
select -AID A00000006203010C0101
send_apdu -sc 0 -APDU 1122334455

(N.B. Ensure that the values of ‘install_for_install’, the ‘select’ and ‘delete’ match the values in the HelloWorld.opt file in C:\java_card_kit-2_2_2\samples\src\com\sun\javacard\samples\HelloWorld\ and if not then alter the HW.txt)

6. Run GpShell HW.txt

>gpshell myinstallscript.txt

Latest Tweets

Microexpert Limited
Researchers devise efficient power converter for internet of things
Microexpert Limited
This captured WWI codebook illustrates an issue that we still face today
Follow Microexpert Limited on Twitter