How to run java card applet

dear friend
i am using java card development kit version 2.2.2. i have downloaded apache-ant-1.7.0-bin .i have tried to run the sample code provided by the kit.i n the kit i have seen a HelloWorld Applet. i have compiled it.using the follwing commands
F:\Program Files\Java\jdk1.6.0_05>set JAVA_HOME=F:\Program Files\Java\jdk1.6.0_0
5
F:\Program Files\Java\jdk1.6.0_05>set PATH=%JC_HOME%\bin;%JAVA_HOME%\bin;%PATH%
F:\Program Files\Java\jdk1.6.0_05>cd..
F:\Program Files\Java>cd..
F:\Program Files>cd..
F:\>cd arun
F:\arun>cd apache-ant-1.7.0-bin\apache-ant-1.7.0\bin
F:\arun\apache-ant-1.7.0-bin\apache-ant-1.7.0\bin>set PATH=%PATH%;F:\arun\apache
-ant-1.7.0-bin\apache-ant-1.7.0\bin
F:\arun\apache-ant-1.7.0-bin\apache-ant-1.7.0\bin>cd..
F:\arun\apache-ant-1.7.0-bin\apache-ant-1.7.0>cd..
F:\arun\apache-ant-1.7.0-bin>cd..
F:\arun>cd java_card_kit-2_2_2
F:\arun\java_card_kit-2_2_2>cd java_card_kit-2_2_2-rr-bin-windows-do\samples
F:\arun\java_card_kit-2_2_2\java_card_kit-2_2_2-rr-bin-windows-do\samples>javac
-g -classpath .\classes;..\lib\api.jar;..\lib\installer.jar src\com\sun\javacard
\samples\HelloWorld\*.java
F:\arun\java_card_kit-2_2_2\java_card_kit-2_2_2-rr-bin-windows-do\samples>javac
-g -classpath .\classes;..\lib\api.jar;..\lib\installer.jar src\com\sun\javacard
\samples\HelloWorld\*.java
F:\arun\java_card_kit-2_2_2\java_card_kit-2_2_2-rr-bin-windows-do\samples>javac
-g -classpath .\classes;..\lib\api.jar;..\lib\installer.jar src\com\sun\javacard
\samples\HelloWorld\*.java
F:\arun\java_card_kit-2_2_2\java_card_kit-2_2_2-rr-bin-windows-do\samples>
and now what i have to do to get the output of this applet? can u please help me with detailed description of te steps and commands and the directory from which i have to use those commands
thanks in advance
bye

Is there any suggestion for my question?.. :(
Thanks in advance..

Similar Messages

  • How to run java signed applet in vista with changing IE security options

    how to run java signed applet in vista with changing IE security options. If i change the IE security settings to low. it works.
    without changing the security setting, how to run.

    j_nanaji9 wrote:
    how to run java signed applet in vista with changing IE security options. If i change the IE security settings to low. it works.
    without changing the security setting, how to run.Can't be done without changing the security setting.

  • How to run Java Card 2.2.1 demo application?

    Hi Friends..
    i want to know how to run Java Card 2.2.1 demo application in Windows environment..
    Sorry, perhaps this question looks like a little bit stupid.. :(
    In Windows, I've set the environment variables for :
    JAVA_HOME : C:\Program Files\Java\jdk1.6.0_03
    JC_HOME : C:\java_card_kit-2_2_1
    and then how to run demo1.scr, etc?.
    Please help me regarding this,
    Thanks in advance..

    Is there any suggestion for my question?.. :(
    Thanks in advance..

  • How to run Java Card Program in a Simulator

    I m Narendra Reddy studying in India and have taken Java Card for my B.E. final year project.
    i also acquire knowledge of Whole Java Card Development Life Cycle but i found much more difficulties to implement those ideas into java card.
    so, Will you please do me a favour and give me a complete solution if possible with an example.
    i also want each step with the commands, from the creation of Class file to the running of prog. in simulator.
    it will be very useful for me to head towards my project.
    Thank you,

    Just for the record,
    Since we are looking at different possibilities, there are couple of ways to achieve simulation/testing environment for current Java Card,
    1. "The Java Card Workstation Development Environment(JCWDE) tool allows the simulated running of Java Card applet as if it were masked in ROM. It immulates Card environment." Although, as Joe mentioned, it does not support;
    - package installation
    - applet instance creation
    - persistent card state
    - firewall
    - transactions
    - transient array clearing
    - remote method invocation
    - applet/package deletion
    Thus you can use 'jcwde' tool in combination of apdutool to test some
    of the Applet behavior(& JCRE) but not all. You have realized this when you tried 'sample' applets.
    2. JCDK2.2 also provide c-reference implementation of the Java Card. This(cref) is more robust way to test Applet. Although the catch with this is that Sun does not have SCSL(Community Source Licensing) program for Java Card(alas!) and this means you can not mask your applet into this reference implementation unless you get hold of source code somehow(source licensing is one(costly) way)
    3. Buy reader/card and figure out how to install applet for
    testing purpose.
    4. Buy kit from JC vendor containing reader/software/cards and use it
    (costly and hard to find JC2.2 implementation)
    1 and 2 are easier but not a real life solution(how many cards with intel/sparc processor anyway?). 3 and 4 are ideal but other way challenging. Yes, probably solution-1 is the right for your purpose.
    regard,

  • How to run Java Card 2.2.2 sample Wallet Application?

    Hi Friends..
    I've downloaded Eclipse Pulsar and Java Card Plugins..
    and i tried to make an empty applicatio, and then i loaded all samples application into my empty application..
    after that, i tried to set AID for Wallet Applet and for package of Wallet Applet..
    I've tried to creates a .CAP file, .EXP file, .JCA file, and scripts file through Eclipse Java Card tools..
    and then what else i've to do?..
    Please give me any suggestion.., because i'm so dizzy.. :(
    Thanks in advance..

    Sorry, i forgot to ask this question..
    Will .cap file installed automatically, when .cap file loaded successfully?
    it means that the all packages and applets would be installed automatically, when that all files loaded successfully?
    Thanks in advance..

  • How to run Java 3D Applet without install java3d

    I've written a java3d applet, and it runs correctly in browser on my computer. Now I want it can be run on other computers which havent' Java3d installed. If the program runs as application, then we can use jnlp and web-start to solve this problem. But what about applet? How can I do it just like the application?
    Pls help me!

    Hello. I read this article too. It sounds interesting but I have some questions. The example is given for win32 and what about other OSs and platforms? Sun provides different libraries for different OS. According to this article it is possible to run applets without previous installation of Java3D and if a user runs Windows 2000, Java3D libraries will be downloaded and installed from the location pointed out by the programmer. But how to do this for all OSs and all platforms and architectures so that if a user doesn't have Java3D installed on his/her computer, might to see the applet in his/her browser? Is it the only way that a programmer needs to include into "loader_singed.jar" all possible libraries for all possible platforms?

  • How to run Java JDBC-Applet in Internet Explorer Browser?

    I developed an java application which uses JDBC thin client driver to fetch data from oracle 8i tables, applet to display some graphics.
    I am able to compile to code in dos prompt.
    Iam unable to run using Appletviewer and IE browser.
    In IE browser it displays applet started in status bar but it displays nothing.
    In appletviewer it gives
    Warning : Can't read appletviewer properties file :c:\.....
    java.security.AccessControlException......security expression specifying database host and port.
    Environment : Oracle 9iDS release 2.0
    Can anybody help me by providing the solution.

    http://java.sun.com/developer/technicalArticles/Security/applets/
    - Saish

  • How to load a java card applet into a java card

    Dear All,
    I am a novice to java card technology..
    I have done some search on how to load a java card applet into a smart card but haven't found a satisfactory answer. I have read about installer.jar and scriptgen tool but I want to load the applet from a java program and not from command line. It would be of great help if somebody can help me out.
    If somebody can share a sample program which load a javacard applet(.CAP file) into a smart card, I will be very thankful.
    I am able to find some client applications which help us send APDU commands and recieve response APDU's to interact with an applet loaded on to the smart card but not application which actually load the applet.
    I have heard of OCF and GP.. some say that OCF technology is outdated and no longer in use.. can somebosy throw some light on this too..
    cheers,
    ganesh

    hi siavash,
    thanks for the quick response.. i checked out GPShell as suggested, it looked like a tool by which one can load an applet on to card and send some sample apdu commands... but I want to load the applet from the code.
    My application should look something like this.. it will be a swing applicaton where I have a drop down with a list of readers, I select the one desired and then click on "LOAD" after inserting a blank java card, at this point my applet which is stored in my DB should get loaded on to the java card. The next step should be to personalize it where I enter the values for the static variables of my applet and click "PERSONALIZE", at this point all these values should be embedded into APDU commands and sent to the java card for processing.
    For achieving this I am yet to find a comprehensive sample or documentation on the net.
    Please help...
    regards,
    ganesh

  • How to create an instance (or instances) of the java card applet?

    Here I have a backend, a host application (a terminal)
    and a Java card that needs to be instanced to multiple cards to different users.
    I wonder how you can make instances of Java card applets of different IDs or PINs.

    933351 wrote:
    Yes, I would like to emulate an environment first, Unfortunately I cannot help with this (never really used this tool).
    I'd like to know also how to install them later on real cards.You need something that can perform the secure channel and card content management functions of the GlobalPlatform card specification. A good starting point is GPShell. It provides a simple scripting interface to be able to:
    1) Authenticate with a card with developer keys
    2) Load you cap file(s)
    3) Instantiate any instances you require (you can have multiple instances from a single applet)
    4) Send arbitrary APDU's to the card for testing.
    GPShell has a README text file that is a good reference and there are sample scripts for a number of card types.
    - Shane

  • How can we create a common function for 2 or more java card applets?

    I have 2 java card applets. They use one common function. But i don't know how to set up it. Anybody knows it, please help me. Please show me step by step to do it. Thank you.

    When insert below line of code in the Test_Class_1.java and Test_Class_2, the Project will be failed:
    byte aP1 = Test_common_function.GetP1((byte)0x02);
    byte aP1 = Test_common_function.GetP1((byte)0x01);
    Here is the source code:
    Test_Class_2.java
    package Test_Class_2;
    import Test_common_function.Test_common_function;
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    public class Test_Class_2 extends Applet
       public static void install(byte[] bArray, short bOffset, byte bLength)
          // GP-compliant JavaCard applet registration
          new Test_Class_2().register(bArray, (short) (bOffset + 1),
                bArray[bOffset]);
       public void process(APDU apdu)
          byte aP1 = Test_common_function.GetP1((byte)0x02);
    }Test_Class_1.java
    package Test_Class_1;
    import Test_common_function.Test_common_function;
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    public class Test_Class_1 extends Applet
       public static void install(byte[] bArray, short bOffset, byte bLength)
          // GP-compliant JavaCard applet registration
          new Test_Class_1().register(bArray, (short) (bOffset + 1),
                bArray[bOffset]);
       public void process(APDU apdu)
          byte aP1 = Test_common_function.GetP1((byte)0x02);
    }Test_common_function.java
    package Test_common_function;
    import javacard.framework.APDU;
    import javacard.framework.ISO7816;
    import javacard.framework.Applet;
    import javacard.framework.ISOException;
    public class Test_common_function extends Applet
       public static void install(byte[] bArray, short bOffset, byte bLength)
          // GP-compliant JavaCard applet registration
          new Test_common_function().register(bArray,
                (short) (bOffset + 1), bArray[bOffset]);
       public void process(APDU apdu)
          // Good practice: Return 9000 on SELECT
          if (selectingApplet())
             return;
          byte[] buf = apdu.getBuffer();
          switch (buf[ISO7816.OFFSET_INS])
             case (byte) 0x00:
                break;
             default:
                // good practice: If you don't know the INStruction, say so:
                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
       public static byte bP1_Class1 = (byte)0x90;
       public static byte bP1_Class2 = (byte)0x90;
       public static byte GetP1(byte idclass)
          return idclass == (byte)0x01? bP1_Class1:bP1_Class2;
    }and here is the trace log (in case of failure)
    cm>  /term "Remote|localhost:60351"
    --Opening terminal
    /card -a a000000003000000 -c com.ibm.jc.CardManagerresetCard with timeout: 0 (ms)
    --Waiting for card...
    ATR=3B F8 13 00 00 81 31 FE 45 4A 43 4F 50 76 32 34    ;.....1.EJCOPv24
        31 B7                                              1.
    IOCTL().
    ATR:
             T = 1                  
    => 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00          ..............
    (578768 nsec)
    <= 6F 65 84 08 A0 00 00 00 03 00 00 00 A5 59 9F 65    oe...........Y.e
        01 FF 9F 6E 06 47 91 01 17 33 00 73 4A 06 07 2A    ...n.G...3.sJ..*
        86 48 86 FC 6B 01 60 0C 06 0A 2A 86 48 86 FC 6B    .H..k.`...*.H..k
        02 02 01 01 63 09 06 07 2A 86 48 86 FC 6B 03 64    ....c...*.H..k.d
        0B 06 09 2A 86 48 86 FC 6B 04 02 15 65 0B 06 09    ...*.H..k...e...
        2B 85 10 86 48 64 02 01 03 66 0C 06 0A 2B 06 01    +...Hd...f...+..
        04 01 2A 02 6E 01 02 90 00                         ..*.n....
    Status: No Error
    cm>  set-key 255/1/DES-ECB/404142434445464748494a4b4c4d4e4f 255/2/DES-ECB/404142434445464748494a4b4c4d4e4f 255/3/DES-ECB/404142434445464748494a4b4c4d4e4f
    cm>  init-update 255
    => 80 50 00 00 08 37 0D D8 24 C9 C8 32 53 00          .P...7..$..2S.
    (1829 usec)
    <= 00 00 DE 81 34 18 39 B7 09 70 FF 02 00 00 3D 02    ....4.9..p....=.
        9C 31 C7 89 7A 8E 57 44 05 A7 67 C7 90 00          .1..z.WD..g...
    Status: No Error
    cm>  ext-auth plain
    => 84 82 00 00 10 D8 BE 91 A3 94 E8 34 18 42 28 F6    ...........4.B(.
        74 EE 50 06 29                                     t.P.)
    (1683 usec)
    <= 90 00                                              ..
    Status: No Error
    cm>  delete -r 01020304050102
    => 80 E4 00 80 09 4F 07 01 02 03 04 05 01 02 00       .....O.........
    (833593 nsec)
    <= 6A 88                                              j.
    Status: Reference data not found
    jcshell: Error code: 6a88 (Reference data not found)
    jcshell: Wrong response APDU: 6A88
    Ignoring expected error
    cm>  delete -r 01020304050103
    => 80 E4 00 80 09 4F 07 01 02 03 04 05 01 03 00       .....O.........
    (769014 nsec)
    <= 6A 88                                              j.
    Status: Reference data not found
    jcshell: Error code: 6a88 (Reference data not found)
    jcshell: Wrong response APDU: 6A88
    Ignoring expected error
    cm>  delete -r 010203040501
    => 80 E4 00 80 08 4F 06 01 02 03 04 05 01 00          .....O........
    (734456 nsec)
    <= 6A 88                                              j.
    Status: Reference data not found
    jcshell: Error code: 6a88 (Reference data not found)
    jcshell: Wrong response APDU: 6A88
    Ignoring expected error
    cm>  upload -c -d -b 250 "D:\WorkSpace\Test_Common_Funcation\bin\Test_common_function\javacard\Test_common_function.cap"
    => 80 E6 02 00 13 06 01 02 03 04 05 01 08 A0 00 00    ................
        00 03 00 00 00 00 00 00 00                         .........
    (1864 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Start loading Header.cap (44 byte)
    => 80 E8 00 00 2C C4 82 03 E3 01 00 25 DE CA FF ED    ....,......%....
        02 02 04 00 01 06 01 02 03 04 05 01 14 54 65 73    .............Tes
        74 5F 63 6F 6D 6D 6F 6E 5F 66 75 6E 63 74 69 6F    t_common_functio
        6E 00                                              n.
    (1607 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Header.cap loaded (44 byte)
    Start loading Directory.cap (36 byte)
    => 80 E8 00 01 24 02 00 21 00 25 00 21 00 0C 00 0B    ....$..!.%.!....
        00 26 00 0E 00 4C 00 0C 00 0D 00 00 00 6F 02 5D    .&...L.......o.]
        00 02 00 00 00 00 01 01 00 00                      ..........
    (1368 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Directory.cap loaded (36 byte)
    Start loading Import.cap (14 byte)
    => 80 E8 00 02 0E 04 00 0B 01 03 01 07 A0 00 00 00    ................
        62 01 01 00                                        b...
    (1096 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Import.cap loaded (14 byte)
    Start loading Applet.cap (15 byte)
    => 80 E8 00 03 0F 03 00 0C 01 08 01 02 03 04 05 01    ................
        01 01 00 08 00                                     .....
    (1188 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Applet.cap loaded (15 byte)
    Start loading Class.cap (17 byte)
    => 80 E8 00 04 11 06 00 0E 00 00 00 80 03 00 FF 00    ................
        07 01 00 00 00 1C 00                               .......
    (1457 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Class.cap loaded (17 byte)
    Start loading Method.cap (79 byte)
    => 80 E8 00 05 4F 07 00 4C 00 01 10 18 8C 00 02 7A    ....O..L.......z
        05 30 8F 00 08 3D 8C 00 00 18 1D 04 41 18 1D 25    .0...=......A..%
        8B 00 01 7A 02 21 18 8B 00 06 60 03 7A 19 8B 00    ...z.!....`.z...
        04 2D 1A 04 25 73 00 09 00 00 00 00 00 0F 11 6D    .-..%s.........m
        00 8D 00 07 7A 02 10 1C 04 6B 07 7C 00 03 70 05    ....z....k.|..p.
        7C 00 05 78 00                                     |..x.
    (1101 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Method.cap loaded (79 byte)
    Start loading StaticField.cap (15 byte)
    => 80 E8 00 06 0F 08 00 0C 00 02 00 00 00 00 00 00    ................
        00 02 90 90 00                                     .....
    (1069 usec)
    <= 00 90 00                                           ...
    Status: No Error
    StaticField.cap loaded (15 byte)
    Start loading ConstantPool.cap (41 byte)
    => 80 E8 00 07 29 05 00 26 00 09 06 00 00 01 03 80    ....)..&........
        03 02 06 80 03 00 05 00 00 00 03 80 0A 01 05 00    ................
        00 01 03 80 03 03 06 80 07 01 01 00 02 00 00       ...............
    (3134 usec)
    <= 00 90 00                                           ...
    Status: No Error
    ConstantPool.cap loaded (41 byte)
    Start loading RefLocation.cap (16 byte)
    => 80 E8 00 08 10 09 00 0D 00 00 00 09 05 06 04 0A    ................
        07 07 13 0A 05 00                                  ......
    (2067 usec)
    <= 00 90 00                                           ...
    Status: No Error
    RefLocation.cap loaded (16 byte)
    Start loading Descriptor.cap (114 byte)
    => 80 E8 00 09 72 0B 00 6F 01 00 01 00 02 00 00 02    ....r..o........
        00 04 00 09 00 00 00 80 03 01 09 00 00 01 80 03    ................
        00 81 00 01 00 14 00 05 00 00 00 00 01 09 00 08    ................
        00 16 00 12 00 00 00 00 07 01 00 1C 00 19 00 1F    ................
        00 00 00 00 02 09 00 3D 00 1D 00 0D 00 00 00 00    .......=........
        00 09 00 14 00 16 00 14 00 1F 00 21 00 1F 00 23    ...........!...#
        00 25 FF FF 01 10 04 B4 31 06 68 00 A1 02 33 01    .%......1.h...3.
        30 01 B0 01 20 02 41 00                            0... .A.
    (1344 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Descriptor.cap loaded (114 byte)
    Start loading Debug.cap (608 byte)
    => 80 E8 00 0A FA 0C 02 5D 00 1A 00 29 54 65 73 74    .......]...)Test
        5F 63 6F 6D 6D 6F 6E 5F 66 75 6E 63 74 69 6F 6E    _common_function
        2F 54 65 73 74 5F 63 6F 6D 6D 6F 6E 5F 66 75 6E    /Test_common_fun
        63 74 69 6F 6E 00 19 6A 61 76 61 63 61 72 64 2F    ction..javacard/
        66 72 61 6D 65 77 6F 72 6B 2F 41 70 70 6C 65 74    framework/Applet
        00 19 54 65 73 74 5F 63 6F 6D 6D 6F 6E 5F 66 75    ..Test_common_fu
        6E 63 74 69 6F 6E 2E 6A 61 76 61 00 0A 62 50 31    nction.java..bP1
        5F 43 6C 61 73 73 31 00 01 42 00 0A 62 50 31 5F    _Class1..B..bP1_
        43 6C 61 73 73 32 00 06 3C 69 6E 69 74 3E 00 03    Class2..<init>..
        28 29 56 00 04 74 68 69 73 00 2B 4C 54 65 73 74    ()V..this.+LTest
        5F 63 6F 6D 6D 6F 6E 5F 66 75 6E 63 74 69 6F 6E    _common_function
        2F 54 65 73 74 5F 63 6F 6D 6D 6F 6E 5F 66 75 6E    /Test_common_fun
        63 74 69 6F 6E 3B 00 07 69 6E 73 74 61 6C 6C 00    ction;..install.
        07 28 5B 42 53 42 29 56 00 06 62 41 72 72 61 79    .([BSB)V..bArray
        00 02 5B 42 00 07 62 4F 66 66 73 65 74 00 01 53    ..[B..bOffset..S
        00 07 62 4C 65 6E 67 74 68 00 07 70 72 6F 63 00    ..bLength..proc.
    (937268 nsec)
    <= 00 90 00                                           ...
    Status: No Error
    => 80 E8 00 0B FA 65 73 73 00 1C 28 4C 6A 61 76 61    .....ess..(Ljava
        63 61 72 64 2F 66 72 61 6D 65 77 6F 72 6B 2F 41    card/framework/A
        50 44 55 3B 29 56 00 04 61 70 64 75 00 19 4C 6A    PDU;)V..apdu..Lj
        61 76 61 63 61 72 64 2F 66 72 61 6D 65 77 6F 72    avacard/framewor
        6B 2F 41 50 44 55 3B 00 03 62 75 66 00 05 47 65    k/APDU;..buf..Ge
        74 50 31 00 04 28 42 29 42 00 07 69 64 63 6C 61    tP1..(B)B..idcla
        73 73 00 14 54 65 73 74 5F 63 6F 6D 6D 6F 6E 5F    ss..Test_common_
        66 75 6E 63 74 69 6F 6E 00 19 00 01 00 00 00 01    function........
        00 02 00 01 00 02 00 00 02 00 04 00 03 00 04 00    ................
        09 00 00 00 00 00 05 00 04 00 09 00 00 00 01 00    ................
        06 00 07 00 01 00 01 02 00 05 00 01 00 01 00 00    ................
        08 00 09 00 00 00 05 00 00 00 04 00 0F 00 0A 00    ................
        0B 00 09 00 08 02 00 12 00 03 00 04 00 00 0C 00    ................
        0D 00 00 00 12 01 00 0E 00 0F 00 00 00 12 02 00    ................
        10 00 04 00 00 00 12 00 00 00 07 00 14 00 08 00    ................
        0D 00 15 00 0E 00 10 00 14 00 11 00 11 00 16 00    ................
    (785421 nsec)
    <= 00 90 00                                           ...
    Status: No Error
    => 80 E8 80 0C 6C 00 11 00 12 00 01 00 1C 02 00 1F    ....l...........
        00 03 00 06 00 00 08 00 09 00 00 00 1F 01 00 13    ................
        00 14 00 00 00 1F 02 00 15 00 0D 00 0C 00 13 00    ................
        00 00 05 00 1B 00 06 00 06 00 1D 00 07 00 0B 00    ................
        20 00 0C 00 17 00 21 00 18 00 1D 00 27 00 1E 00     .....!.....'...
        1E 00 29 00 16 00 17 00 09 00 3D 02 00 0D 00 01    ..).......=.....
        00 01 00 00 18 00 04 00 00 00 0D 00 00 00 0C 00    ................
        2F 00                                              /.
    (1986 usec)
    <= 00 90 00                                           ...
    Status: No Error
    Debug.cap loaded (608 byte)
    Load report:
      999 bytes loaded in 0.0 seconds
      effective code size on card:
          + package AID       6
          + applet AIDs       15
          + classes           17
          + methods           79
          + statics           2
          + exports           0
            overall           119  bytes
    cm>  install -i 0102030405010101  -q C9#() 010203040501 0102030405010101
    => 80 E6 0C 00 1F 06 01 02 03 04 05 01 08 01 02 03    ................
        04 05 01 01 01 08 01 02 03 04 05 01 01 01 01 00    ................
        02 C9 00 00 00                                     .....
    (2346 usec)
    <= 00 90 00                                           ...
    Status: No Error
    cm>  upload -c -d -b 250 "D:\WorkSpace\Test_Common_Funcation\bin\Test_Class_2\javacard\Test_Class_2.cap"
    jcshell: Cannot read <D:\WorkSpace\Test_Common_Funcation\bin\Test_Class_2\javacard\Test_Class_2.cap>: java.io.FileNotFoundException: D:\WorkSpace\Test_Common_Funcation\bin\Test_Class_2\javacard\Test_Class_2.cap (The system cannot find the path specified)
    cm>  install -i 0102030405010303  -q C9#() 01020304050103 0102030405010303
    => 80 E6 0C 00 20 07 01 02 03 04 05 01 03 08 01 02    .... ...........
        03 04 05 01 03 03 08 01 02 03 04 05 01 03 03 01    ................
        00 02 C9 00 00 00                                  ......
    (1231 usec)
    <= 6A 88                                              j.
    Status: Reference data not found
    jcshell: Error code: 6a88 (Reference data not found)
    jcshell: Wrong response APDU: 6A88
    Unexpected error; aborting executionThank very much!
    Edited by: WhoKnows on Apr 20, 2012 9:32 PM

  • Java application communicate with java card applet without java card

    Can I write java application to communicate with java card applet without using java card?
    Can I send APDU to java card applet on computer(not install in java card)? If it's not, how can I write?
    Best Regard,
    Thanawan

    Your JCOP simulator implements a JCVM/JCRE according
    to specs. The CREF does that same thing excepts it's
    only simulates the API without crypto or third party
    applets. JCOP simulator is more then that. They are using thesame_ codebase for simulator and for oncard JCVM. Basically you are dealing with the same environment in both cases.

  • Urgent ! writing a java card applet -APDU problem

    hi
    i'm fairly new to the java programming language. i'm trying to write an RSA java card applet to run on a java card simulator.
    I am not sure at all what code i need to write for the CLA byte in the command APDU and what code i need to write for the INS byte in the command APDU, and where exactly to put it in my program.
    if anybody knows please could you help me out.
    So far i have written the code below.
    thanx
    louise
    import javacard.framework.*;
    import java.math.*;
    import java.util.*;
    /*the public key is the public part of the key. Anyone
    can have it. It can only encrypt data, not decrypt.*/
    public class publickey extends Applet{
    //code of the CLA byte in the command APDU header
    final static byte publickey_CLA = (byte)0x00;
    //max number of characters for text message is 60
    final static char MAX_TXT_MSG = 0x3c;
    //MAX number of tries (3) before PIN is blocked
    final static byte PIN_TRY_LIMIT = (byte)0x03;
    //size of PIN must be 4 digits long
    final static byte PIN_SIZE = (byte)0x04;
    //below status word(SW) values are returned by applet
    //in certain circumstances:
    //signal that the PIN verification failed
    final static short SW_PIN_VERIFICATION_FAIL = 0x6300;
    //signal that PIN validation required for txt msging
    final static short SW_PIN_VERIFICATION_REQUIRED = 0x630;
    //instance variables declaration
    OwnerPIN pin; //variable for holding owners pin
    BigInteger n,e;
    String owner;//variable for holding owners name
    /*make a public key. Do not do it yourself, but
    make a public key from a private key.*/
    publickey(String iowner,BigInteger in,BigInteger ie){
    owner=iowner;
    n=in;
    e=ie;
    public void process (APDU apdu) {
    byte[] buffer = apdu.getBuffer();
    //check Select APDU command
    if((buffer[ISO7816.OFFSET_CLA] ==0) &&
    (buffer[ISO7816.OFFSET_INS] ==(byte) (0xA4)) )
    return;
    if(buffer[ISO7816.OFFSET_CLA] !=publickey_CLA)
    ISOException.throwIt
    (ISO7816.SW_CLA_NOT_SUPPORTED);
    /*read the key back from a string.*/
    publickey(String from){
    StringTokenizer st=new StringTokenizer(from," ");
    owner=st.nextToken();
    n=readBI(st.nextToken());
    e=readBI(st.nextToken());
    /*use the key to encrypt a 'message' m. m should be a
    number from 1 to n (n not included).
    use makemessage to convert your message to a BigInteger.
    BigInteger encrypt(BigInteger m){
    return m.modPow(e,n);
    /*make a string from this key.*/
    public String toString(){
    return owner+" "+printBI(n)+" "+printBI(e);
    /*help methods for reading and writing:*/
    final static int radix=36;
    static String printBI(BigInteger b){
    return b.toString(radix);
    static BigInteger readBI(String s){
    return new BigInteger(s,radix);
    /* these methods convert an arbitrary message,
    in the form of an array of bytes, to a message
    suitable for encryption. To do this random bits
    are added (this is needed to make cracking of the
    system harder), and it is converted to a BigInteger.*/
    BigInteger makemessage(byte[] input){
    /*to understand this part of the program,
    read the description of the BigInteger constructor
    (in the standard java help). */
    if(input.length>128 ||
    input.length*8+24>=n.bitLength())
    return new BigInteger("0"); //error! message to long.
    byte[] paddedinput=new byte[n.bitLength()/8-1];
    for(int i=0;i<input.length;i++)
    paddedinput[i+1]=input;
    paddedinput[0]=(byte)input.length;
    for(int i=input.length+1;i<paddedinput.length;i++)
    paddedinput[i]=(byte)(Math.random()*256);
    return new BigInteger(paddedinput);
    /*the inverse of makemessage.*/
    static byte[] getmessage(BigInteger b){
    byte[] paddedoutput=b.toByteArray();
    byte[] output=new byte[paddedoutput[0]];
    for(int i=0;i<output.length;i++)
    output[i]=paddedoutput[i+1];
    return output;
    class privatekey{
    /*the data of a key*/
    BigInteger n,e,d;
    String owner;
    int bits;
    Random ran;
    /*unimportant things, needed for calculations:*/
    static int certainty=32;
    static BigInteger one=new BigInteger("1"),
    three=new BigInteger("3"),
    seventeen=new BigInteger("17"),
    k65=new BigInteger("65537");
    /*make a new key. supply the name of the owner of the
    key, and the number of bits.
    owner: all spaces will be replaced with underscores.
    bits: the more bits the better the security. Every
    value above 500 is 'safe'. If you are a really paranoid
    person, you should use 2000.*/
    privatekey(String iowner,int ibits){
    BigInteger p,q;
    bits=ibits;
    owner=iowner.replace(' ','_');//remove spaces from owner name.
    ran=new Random();
    p=new BigInteger(bits/2,certainty,ran);
    q=new BigInteger((bits+1)/2,certainty,ran);
    n=p.multiply(q);
    BigInteger fi_n=fi(p,q);
    e=chooseprimeto(fi_n);
    d=e.modInverse(fi_n);
    /*read the key back from a string*/
    privatekey(String from){
    StringTokenizer st=new StringTokenizer(from," ");
    st.nextToken();
    n=readBI(st.nextToken());
    e=readBI(st.nextToken());
    d=readBI(st.nextToken());
    /*some help methods:*/
    static BigInteger fi(BigInteger prime1,BigInteger prime2){
    return prime1.subtract(one).multiply(prime2.subtract(one));
    static BigInteger BI(String s)
    {return new BigInteger(s);}
    BigInteger chooseprimeto(BigInteger f){
    /*returns a number relatively prime to f.
    this number is not chosen at random, it first
    tries a few primes with few 1's in it. This
    doesn't matter for security, but speeds up computations.*/
    if(f.gcd(three).equals(one))
    return three;
    if(f.gcd(seventeen).equals(one))
    return seventeen;
    if(f.gcd(k65).equals(one))
    return k65;
    BigInteger num;
    do{
    num=new BigInteger(16,ran);
    }while(!f.gcd(num).equals(one));
    return num;
    final static int radix=36;
    static String printBI(BigInteger b){
    return b.toString(radix);
    static BigInteger readBI(String s){
    return new BigInteger(s,radix);
    /*returns the public key of this private key.*/
    publickey getpublickey(){
    return new publickey(owner,n,e);
    /*the same encryption that the public key does.*/
    BigInteger encrypt(BigInteger m){
    return m.modPow(e,n);
    /*decryption is the opposite of encryption: it
    brings the original message back.*/
    BigInteger decrypt(BigInteger m){
    return m.modPow(d,n);
    public String toString(){
    return owner+" "+printBI(n)+" "+printBI(e)+" "+printBI(d);
    /*this main demonstrates the use of this program.*/
    public static void main(String[] ps){
    say("************ make key:");
    privatekey priv=new privatekey("sieuwert",92);
    publickey pub=priv.getpublickey();
    say("the public key:"+priv);
    say("************ encrypt message:");
    byte[] P="RUOK?".getBytes();
    BigInteger Pc=pub.makemessage(P);
    say("converted:\t"+printBI(Pc));
    BigInteger C=pub.encrypt(Pc);
    say("coded message: "+printBI(C));
    say("************ decrypt message:");
    BigInteger Pc2=priv.decrypt(C);
    say("decoded:\t"+printBI(Pc2));
    byte[] P2=publickey.getmessage(Pc2);
    say("deconverted: "+new String(P2));
    static void say(String s){
    System.out.println(s);

    Command APDU is not written in your source code, rather it is sent from PC or programmed Card Acceptance Device/ Card Reader/ Terminal.
    The code installed in the Java Card should be able to handle the Command APDU received and process it accordingly, and finally your code should be able to send out response APDU.
    You may think your code as a decoder, to retrieve each byte (CLA, INS, P1, P2, DATA, LC) using the Java Card API, you should be able to do it.
    Also, I notice in your code that you want to work out with strings, but Java Card does not support strings, chars, long, float, double ...
    to send out reponse APDU, there are certain steps that you can use, not just simply print like ordinary J2SE may use.
    hope this will help u

  • Java card applet space

    I am working on a project related to java card applet development. My project consists of 4 java classes which are used to store date of created objects, and a java card applet which contains method that enables me to de some kind of actions on the created objects, such as create a new object of a specified class or edited it and son on.
    Now I have 2 classes done ; first one is called Odemeler which contains variables of type byte and the second one is called SadakatUygulamalar which contains   variables.
    Inside the class I have defined 2 arrays, one of type Odemeler and the other of type SadakatUygulamalar and I set their size to be 200. I have tried to create 100 object of kind Odemeler and to store them in the array
    but the applet is able to store up to 92 object, at the other hand after creating those objects and storing them I am not able to store objects of type SadakatUygulamalar.
    Is this problem related to the applet size or what ?? any help please
    The applet code is here :
    package sTez_1;
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.JCSystem;
    import javacard.framework.Util;
    public class TestApplet1 extends Applet {
         private static Odeme[] odemeArray;
         private static SadakatUygulamalar[] uygulamaArray;
         private static short index = 00;
         private static short index2 = 00;
         private static byte[] result;
         private static byte[] result2;
         private static short res_index =00;
         private static short res2_index =00;
         private static short FirmaIDFlag = 0;
         private static final byte ODEME_CLA = (byte) 0xB0;
         private static final byte UYGULAMA_CLA = (byte) 0xA0;
         private static final byte ODEME_INS_CREATE_PROFILE = (byte) 0x10;
         private static final byte UYGULAMA_INS_CREATE_PROFILE = (byte) 0x20;
         private static final byte ODEME_INS_GET_PROFILE = (byte) 0x30;
         private static final byte ODEME_INS_LIST_SOME = (byte) 0x35;
         private static final byte ODEME_INS_VIEW_PROFILE = (byte) 0x37;
         private static final byte ODEME_INS_GET_PUAN_VIA_FIRMA = (byte) 0x38;
         private static final byte ODEME_INS_GET_ALISVERIS_VIA_KAT = (byte) 0x39;
         private static final byte UYGULAMA_INS_GET_PROFILE = (byte) 0x40;
         private static final byte UYGULAMA_INS_LIST_ALL = (byte) 0x50;
         private static final byte UYGULAMA_INS_UPDATE_ID = (byte) 0x60;
         private static final byte UYGULAMA_INS_UPDATE_NAME = (byte) 0x80;
         private static final byte UYGULAMA_INS_SEARCH = (byte) 0x90;
         private static final byte SPLIT_PARTS = (byte) 0x2C;
         private static final short CLA_ERROR = (short) 0x13;
         private static final short INS_ERROR = (short) 0x14;
         private static final short NO_SUCH_INDEX = (short) 0x15;
         private static final short NO_DATA_FOUND = (short) 0x16;
         private static final short FIRMA_ID_IN_USE = (short) 0x9C;
         private static final short ODEME_ARRAY_FULL = (short) 0x18;
         private TestApplet1() {
              odemeArray = new Odeme[(short) 250];
              uygulamaArray = new SadakatUygulamalar[(short) 200];
              register();
         public static void install(byte bArray[], short bOffset, byte bLength)
                   throws ISOException {
              new TestApplet1();
         public void process(APDU apdu) throws ISOException {
              // TODO Auto-generated method stub
              if (selectingApplet())
                   return;
              byte[] buffer = apdu.getBuffer();
              byte INS = (byte) (buffer[ISO7816.OFFSET_INS] & 0xFF);
              switch (INS) {
              case ODEME_INS_CREATE_PROFILE:
                   odemeCreateProfile(apdu);
                   break;
              case UYGULAMA_INS_CREATE_PROFILE:
                   uygulamaCreateProfile(apdu);
                   break;
              case ODEME_INS_GET_PROFILE:
                   odemeGetProfile(apdu);
                   break;
              case ODEME_INS_LIST_SOME:
                   odemeListSome(apdu);
                   break;
              case ODEME_INS_VIEW_PROFILE:
                   odemeViewProfile(apdu);
                   break;
              case ODEME_INS_GET_PUAN_VIA_FIRMA:
                   odemeGetPuanByFirma(apdu);
                   break;
              case ODEME_INS_GET_ALISVERIS_VIA_KAT:
                   odemeGetAlisverisByKat(apdu);
                   break;
              case UYGULAMA_INS_GET_PROFILE:
                   uygulamaGetProfile(apdu);
                   break;
              case UYGULAMA_INS_UPDATE_ID:
                   uygulamaUpdateID(apdu);
                   break;
              case UYGULAMA_INS_UPDATE_NAME:
                   uygulamaUpdateName(apdu);
                   break;
              case UYGULAMA_INS_LIST_ALL:
                   uygulamaListAll(apdu);
                   break;     
              case UYGULAMA_INS_SEARCH:
                   uygulamaSearch(apdu);
                   break;
              default:
                   ISOException.throwIt(INS_ERROR);
         public void odemeCreateProfile(APDU apdu) {
              byte[] buffer = apdu.getBuffer();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              JCSystem.beginTransaction();
              short fieldIndex = 0;
              short field1counter = 0;
              short field2counter = 0;
              short field3counter = 0;
              short field4counter = 0;
              short field5counter = 0;
              short field6counter = 0;
              short field7counter = 0;
              short field8counter = 0;
              short field9counter = 0;
              short field10counter = 0;
              short field11counter = 0;
              short field12counter = 0;
              short field13counter = 0;
              short field14counter = 0;
              for (short i = 0; i < lc; i++) {
                   fieldIndex++;
                   field1counter++;
                   if (buffer[(short) (5 + i)] == SPLIT_PARTS)
                        i = lc;
              for (short j = fieldIndex; j < lc; j++) {
                   fieldIndex++;
                   field2counter++;
                   if (buffer[(short) (5 + j)] == SPLIT_PARTS)
                        j = lc;
              for (short k = fieldIndex; k < lc; k++) {
                   fieldIndex++;
                   field3counter++;
                   if (buffer[(short) (5 + k)] == SPLIT_PARTS)
                        k = lc;
              for (short h = fieldIndex; h < lc; h++) {
                   fieldIndex++;
                   field4counter++;
                   if (buffer[(short) (5 + h)] == SPLIT_PARTS)
                        h = lc;
              for (short u = fieldIndex; u < lc; u++) {
                   fieldIndex++;
                   field5counter++;
                   if (buffer[(short) (5 + u)] == SPLIT_PARTS)
                        u = lc;
              for (short u1 = fieldIndex; u1 < lc; u1++) {
                   fieldIndex++;
                   field6counter++;
                   if (buffer[(short) (5 + u1)] == SPLIT_PARTS)
                        u1 = lc;
              for (short u2 = fieldIndex; u2 < lc; u2++) {
                   fieldIndex++;
                   field7counter++;
                   if (buffer[(short) (5 + u2)] == SPLIT_PARTS)
                        u2 = lc;
              for (short u3 = fieldIndex; u3 < lc; u3++) {
                   fieldIndex++;
                   field8counter++;
                   if (buffer[(short) (5 + u3)] == SPLIT_PARTS)
                        u3 = lc;
              for (short u4 = fieldIndex; u4 < lc; u4++) {
                   fieldIndex++;
                   field9counter++;
                   if (buffer[(short) (5 + u4)] == SPLIT_PARTS)
                        u4 = lc;
              for (short u5 = fieldIndex; u5 < lc; u5++) {
                   fieldIndex++;
                   field10counter++;
                   if (buffer[(short) (5 + u5)] == SPLIT_PARTS)
                        u5 = lc;
              for (short u6 = fieldIndex; u6 < lc; u6++) {
                   fieldIndex++;
                   field11counter++;
                   if (buffer[(short) (5 + u6)] == SPLIT_PARTS)
                        u6 = lc;
              for (short u7 = fieldIndex; u7 < lc; u7++) {
                   fieldIndex++;
                   field12counter++;
                   if (buffer[(short) (5 + u7)] == SPLIT_PARTS)
                        u7 = lc;
              for (short u8 = fieldIndex; u8 < lc; u8++) {
                   fieldIndex++;
                   field13counter++;
                   if (buffer[(short) (5 + u8)] == SPLIT_PARTS)
                        u8 = lc;
              for (short u9 = fieldIndex; u9 < lc; u9++) {
                   fieldIndex++;
                   field14counter++;
                   if (buffer[(short) (5 + u9)] == SPLIT_PARTS)
                        u9 = lc;
              short cc = 5;
              byte[] _id = new byte[field1counter];
              for (short i1 = 0; i1 < (short) _id.length; i1++)
                   _id[i1] = buffer[(short) (cc + i1)];
            cc = (short)(cc + field1counter);
              byte[] _tarih = new byte[field2counter];
              for (short j1 = 0; j1 < (short) _tarih.length; j1++)
                   _tarih[j1] = buffer[(short) (cc + j1)];
              cc = (short)(cc + field2counter);
              byte[] _saat = new byte[field3counter];
              for (short j2 = 0; j2 < (short) _saat.length; j2++)
                   _saat[j2] = buffer[(short) (cc + j2)];
              cc = (short)(cc + field3counter);  
              byte[] _firma = new byte[field4counter];
              for (short j3 = 0; j3 < (short) _firma.length; j3++)
                   _firma[j3] = buffer[(short) (cc + j3)];
              cc = (short)(cc + field4counter);
              byte[] _kategori = new byte[field5counter];
              for (short j4 = 0; j4 < (short) _kategori.length; j4++)
                   _kategori[j4] = buffer[(short) (cc + j4)];
              cc = (short)(cc + field5counter);
              byte[] _tutar = new byte[field6counter];
              for (short j5 = 0; j5 < (short) _tutar.length; j5++)
                   _tutar[j5] = buffer[(short) (cc + j5)];
              cc = (short)(cc + field6counter);
              byte[] _birim = new byte[field7counter];
              for (short j6 = 0; j6 < (short) _birim.length; j6++)
                   _birim[j6] = buffer[(short) (cc + j6)];
              cc = (short)(cc + field7counter);
              byte[] _ulke = new byte[field8counter];
              for (short j7 = 0; j7 < (short) _ulke.length; j7++)
                   _ulke[j7] = buffer[(short) (cc + j7)];
              cc = (short)(cc + field8counter);
              byte[] _sehir = new byte[field9counter];
              for (short j8 = 0; j8 < (short) _sehir.length; j8++)
                   _sehir[j8] = buffer[(short) (cc + j8)];
              cc = (short)(cc + field9counter);
              byte[] _ilce = new byte[field10counter];
              for (short j9 = 0; j9 < (short) _ilce.length; j9++)
                   _ilce[j9] = buffer[(short) (cc + j9)];
              cc = (short)(cc + field10counter);
              byte[] _aid = new byte[field11counter];
              for (short j10 = 0; j10 < (short) _aid.length; j10++)
                   _aid[j10] = buffer[(short) (cc + j10)];
              cc = (short)(cc + field11counter);
              byte[] _banka = new byte[field12counter];
              for (short j11 = 0; j11 < (short) _banka.length; j11++)
                   _banka[j11] = buffer[(short) (cc + j11)];
              cc = (short)(cc + field12counter);
              byte[] _taksit = new byte[field13counter];
              for (short j12 = 0; j12 < (short) _taksit.length; j12++)
                   _taksit[j12] = buffer[(short) (cc + j12)];
              cc = (short)(cc + field13counter);
              byte[] _puan = new byte[field14counter];
              for (short j13 = 0; j13 < (short) _puan.length; j13++)
                   _puan[j13] = buffer[(short) (cc + j13)];
              cc = (short)(cc + field3counter);
              Odeme m = new Odeme(_id, _tarih, _saat, _firma, _kategori, _tutar, _birim, _ulke, _sehir, _ilce, _aid, _banka, _taksit, _puan);
              if(index2 >= (short)odemeArray.length)
                   ISOException.throwIt(ODEME_ARRAY_FULL);
              odemeArray[index2] = m;
              index2++;
              JCSystem.commitTransaction();
              buffer[0] = (byte)index2;
              apdu.setOutgoingAndSend((short) 0, (short) 1);
         public void odemeGetProfile(APDU apdu) {
              byte[] buffer = apdu.getBuffer();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              byte[] sent_id = new byte[lc];
              for (short i5 = 0; i5 < lc; i5++)
                   sent_id[i5] = buffer[(short) (5 + i5)];
              for (short h = 0; h < index2; h++) {
                   Odeme m = odemeArray[h];
                   byte[] _id = m.getID();
                   if (equals(sent_id, _id)) {
                        byte[] banka = m.getBanka();
                        byte[] sehir = m.getSehir();
                        byte[] firma = m.getFirma();
                        short counter = 0;
                        for (short i = 0; i < (short) banka.length; i++)
                             buffer[i] = banka;
                        counter = (short) banka.length;
                        for (short j = 0; j < (short) sehir.length; j++)
                             buffer[(short) (counter + j)] = sehir[j];
                        counter = (short) (counter + sehir.length);
                        for (short j = 0; j < (short) firma.length; j++)
                             buffer[(short) (counter + j)] = firma[j];
                        counter = (short) (counter + firma.length);
                        apdu.setOutgoingAndSend((short) 0, counter);
         public void odemeGetPuanByFirma(APDU apdu)
              byte[] buffer = apdu.getBuffer();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              byte[] puan = null;
              byte[] res = new byte[200];
              byte[] fname = new byte[lc];
              for(short t = 0; t < lc; t++)
                   fname[t] = buffer[(short)(t + 5)];
              short counter = 0;
              for(short z = 0; z < index2 ; z++)
                   Odeme m = odemeArray[z];
                   byte[] _name = m.getFirma();
                   if (equals(fname, _name)) {
                        puan = m.getKazanilanpuan();
                        Util.arrayCopy(puan, (short)0, res, counter, (short)puan.length);
                        counter = (short)(counter + puan.length);
                        res[counter] = (byte)0x7C;
                        counter++;
              Util.arrayCopy(res, (short)0, buffer, (short)0, (short)counter);
              apdu.setOutgoingAndSend((short)0, (short)counter);
         public void odemeGetAlisverisByKat(APDU apdu)
              byte[] buffer = apdu.getBuffer();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              byte[] alisveris = null;
              byte[] res = new byte[200];
              byte[] kat = new byte[lc];
              for(short t = 0; t < lc; t++)
                   kat[t] = buffer[(short)(t + 5)];
              short counter = 0;
              for(short z = 0; z < index2 ; z++)
                   Odeme m = odemeArray[z];
                   byte[] _kategori = m.getKategori();
                   if (equals(kat, _kategori)) {
                        alisveris = m.getTutar();
                        Util.arrayCopy(alisveris, (short)0, res, counter, (short)alisveris.length);
                        counter = (short)(counter + alisveris.length);
                        res[counter] = (byte)0x7C;
                        counter++;
              Util.arrayCopy(res, (short)0, buffer, (short)0, (short)counter);
              apdu.setOutgoingAndSend((short)0, (short)counter);
         public void odemeListSome(APDU apdu)
              byte[] buffer = apdu.getBuffer();
              result2 = new byte[(short) 200];
              byte[] id = null, sehir = null, _banka = null;
              if(index2 == 0)
                   ISOException.throwIt(NO_DATA_FOUND);
              for(short r = 0; r < index2; r++)
                   Odeme m = odemeArray[r];
                   _id = m.getID();
                   _sehir = m.getSehir();
                   _banka = m.getBanka();
                   copyData2(_id, sehir, banka);
              Util.arrayCopy(result2, (short)0, buffer, (short)0, res2_index);
              result2 = null;
              short len = res2_index;
              res2_index = 00;
              apdu.setOutgoingAndSend((short)0, len);
         public void odemeViewProfile(APDU apdu)
              byte[] buffer = apdu.getBuffer();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              byte[] id = new byte[lc];
              for (short j3 = 0; j3 < lc; j3++)
                   id[j3] = buffer[(short) (5 + j3)];
              for (short h = 0; h < index2; h++) {
                   Odeme m = odemeArray[h];
                   byte[] H_id = m.getID();
                   if (equals(id, H_id)) {
                        byte[] tarih = m.getTarih();
                        byte[] saat = m.getSaat();
                        byte[] firma = m.getFirma();
                        byte[] kategori = m.getKategori();
                        byte[] tutar = m.getTutar();
                        byte[] birim = m.getParabirimi();
                        byte[] ulke = m.getUlke();
                        byte[] sehir = m.getSehir();
                        byte[] ilce = m.getIlce();
                        byte[] aid = m.getAID();
                        byte[] banka = m.getBanka();
                        byte[] taksit = m.getTaksitsayisi();
                        byte[] puan = m.getKazanilanpuan();
                        short counter1 = 0;
                        Util.arrayCopy(tarih, (short)0, buffer, (short)0, (short)tarih.length);
                        counter1 = (short)(counter1 + tarih.length);
                        Util.arrayCopy(saat, (short)0, buffer, counter1, (short)saat.length);
                        counter1 = (short)(counter1 + saat.length);
                        Util.arrayCopy(firma, (short)0, buffer, counter1, (short)firma.length);
                        counter1 = (short)(counter1 + firma.length);
                        Util.arrayCopy(kategori, (short)0, buffer, counter1, (short)kategori.length);
                        counter1 = (short)(counter1 + kategori.length);
                        Util.arrayCopy(tutar, (short)0, buffer, counter1, (short)tutar.length);
                        counter1 = (short)(counter1 + tutar.length);
                        Util.arrayCopy(birim, (short)0, buffer, counter1, (short)birim.length);
                        counter1 = (short)(counter1 + birim.length);
                        Util.arrayCopy(ulke, (short)0, buffer, counter1, (short)ulke.length);
                        counter1 = (short)(counter1 + ulke.length);
                        Util.arrayCopy(sehir, (short)0, buffer, counter1, (short)sehir.length);
                        counter1 = (short)(counter1 + sehir.length);
                        Util.arrayCopy(ilce, (short)0, buffer, counter1, (short)ilce.length);
                        counter1 = (short)(counter1 + ilce.length);
                        Util.arrayCopy(aid, (short)0, buffer, counter1, (short)aid.length);
                        counter1 = (short)(counter1 + aid.length);
                        Util.arrayCopy(banka, (short)0, buffer, counter1, (short)banka.length);
                        counter1 = (short)(counter1 + banka.length);
                        Util.arrayCopy(taksit, (short)0, buffer, counter1, (short)taksit.length);
                        counter1 = (short)(counter1 + taksit.length);
    Util.arrayCopy(puan, (short)0, buffer, counter1, (short)puan.length);
    counter1 = (short)(counter1 + puan.length);
                        apdu.setOutgoingAndSend((short) 0, counter1);
         public void uygulamaCreateProfile(APDU apdu) {
              byte[] buffer = apdu.getBuffer();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              // JCSystem.beginTransaction();
              JCSystem.beginTransaction();
              short fieldIndex = 0;
              short field1counter = 0;
              short field2counter = 0;
              short field3counter = 0;
              // byte test;
              for (short i = 0; i < lc; i++) {
                   fieldIndex++;
                   field1counter++;
                   if (buffer[(short) (5 + i)] == SPLIT_PARTS)
                        i = lc;
              for (short j = fieldIndex; j < lc; j++) {
                   fieldIndex++;
                   field2counter++;
                   if (buffer[(short) (5 + j)] == SPLIT_PARTS)
                        j = lc;
              for (short k = fieldIndex; k < lc; k++) {
                   fieldIndex++;
                   field3counter++;
                   if (buffer[(short) (5 + k)] == SPLIT_PARTS)
                        k = lc;
              byte[] uygulama_id = new byte[field1counter];
              for (short i1 = 0; i1 < (short) uygulama_id.length; i1++)
                   uygulama_id[i1] = buffer[(short) (5 + i1)];
              byte[] firma_id = new byte[field2counter];
              for (short j1 = 0; j1 < (short) firma_id.length; j1++)
                   firma_id[j1] = buffer[(short) (5 + field1counter + j1)];
    getFirmaIDFlag(firma_id);
    if(FirmaIDFlag == 1)
         ISOException.throwIt(FIRMA_ID_IN_USE);
              byte[] firma_ismi = new byte[field3counter];
              for (short j2 = 0; j2 < (short) firma_ismi.length; j2++)
                   firma_ismi[j2] = buffer[(short) (5 + field1counter + field2counter + j2)];
              SadakatUygulamalar su = new SadakatUygulamalar(uygulama_id, firma_id,
                        firma_ismi);
              uygulamaArray[index] = su;
              index++;
              JCSystem.commitTransaction();
              buffer[0] = (byte) index;
              apdu.setOutgoingAndSend((short) 0, (short) 1);
         public void uygulamaGetProfile(APDU apdu) {
              byte[] buffer = apdu.getBuffer();
              short p1 = (short) (buffer[ISO7816.OFFSET_P1]);
              if (p1 >= index)
                   ISOException.throwIt(NO_SUCH_INDEX);
              SadakatUygulamalar su = uygulamaArray[p1];
              byte[] uygulama_id = su.getUygulama_id();
              byte[] firma_id = su.getFirma_id();
              byte[] firma_ismi = su.getFirma_ismi();
              short counter = 0;
              for (short i = 0; i < (short) uygulama_id.length; i++)
                   buffer[i] = uygulama_id[i];
              counter = (short) uygulama_id.length;
              for (short j = 0; j < (short) firma_id.length; j++)
                   buffer[(short) (counter + j)] = firma_id[j];
              counter = (short) (counter + firma_id.length);
              for (short j = 0; j < (short) firma_ismi.length; j++)
                   buffer[(short) (counter + j)] = firma_ismi[j];
              counter = (short) (counter + firma_ismi.length);
              apdu.setOutgoingAndSend((short) 0, counter);
         public void uygulamaUpdateID(APDU apdu) {
              byte[] buffer = apdu.getBuffer();
              short p1 = (short) (buffer[ISO7816.OFFSET_P1]);
              if (p1 >= index)
                   ISOException.throwIt(NO_SUCH_INDEX);
              JCSystem.beginTransaction();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              SadakatUygulamalar su = uygulamaArray[p1];
              byte[] newFirmaID = new byte[lc];
              for (short i = 0; i < lc; i++)
                   newFirmaID[i] = buffer[(short) (5 + i)];
              su.setFirma_id(newFirmaID);
              JCSystem.commitTransaction();
              byte[] currentFirmaID = su.getFirma_id();
              for (short k = 0; k < (short) currentFirmaID.length; k++)
                   buffer[k] = currentFirmaID[k];
              apdu.setOutgoingAndSend((short) 0, (short) currentFirmaID.length);
         public void uygulamaUpdateName(APDU apdu) {
              byte[] buffer = apdu.getBuffer();
              short p1 = (short) (buffer[ISO7816.OFFSET_P1]);
              if (p1 >= index)
                   ISOException.throwIt(NO_SUCH_INDEX);
              JCSystem.beginTransaction();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              SadakatUygulamalar su = uygulamaArray[p1];
              byte[] newFirmaName = new byte[lc];
              for (short i = 0; i < lc; i++)
                   newFirmaName[i] = buffer[(short) (5 + i)];
              su.setFirma_ismi(newFirmaName);
              JCSystem.commitTransaction();
              byte[] currentFirmaName = su.getFirma_ismi();
              for (short k = 0; k < (short) currentFirmaName.length; k++)
                   buffer[k] = currentFirmaName[k];
              apdu.setOutgoingAndSend((short) 0, (short) currentFirmaName.length);
         public static boolean equals(byte[] b1, byte[] b2) {
              if (b1 == null && b2 == null) {
                   return true;
              if (b1 == null || b2 == null) {
                   return false;
              if ((short) b1.length != (short) b2.length) {
                   return false;
              for (short i = 0; i < (short) b1.length; i++) {
                   if (b1[i] != b2[i]) {
                        return false;
              return true;
         public void uygulamaSearch(APDU apdu) {
              byte[] buffer = apdu.getBuffer();
              short lc = (short) buffer[ISO7816.OFFSET_LC];
              byte[] f_id = new byte[lc];
              for (short i3 = 0; i3 < lc; i3++)
                   f_id[i3] = buffer[(short) (5 + i3)];
              for (short h = 0; h < index; h++) {
                   SadakatUygulamalar su = uygulamaArray[h];
                   byte[] H_Firma_id = su.getFirma_id();
                   if (equals(f_id, H_Firma_id)) {
                        byte[] H_Uygulama_id = su.getUygulama_id();
                        byte[] H_Firma_ismi = su.getFirma_ismi();
                        short counter1 = 0;
                        for (short k1 = 0; k1 < (short) H_Uygulama_id.length; k1++)
                             buffer[k1] = H_Uygulama_id[k1];
                        counter1 = (short) H_Uygulama_id.length;
                        for (short j2 = 0; j2 < (short) H_Firma_ismi.length; j2++)
                             buffer[(short) (counter1 + j2)] = H_Firma_ismi[j2];
                        counter1 = (short) (counter1 + H_Firma_ismi.length);
                        apdu.setOutgoingAndSend((short) 0, counter1);
         public void uygulamaListAll(APDU apdu)
              byte[] buffer = apdu.getBuffer();
              result = new byte[(short) 200];
              byte[] u_id = null, f_id = null, f_isim = null;
              for(short r = 0; r < index; r++)
                   SadakatUygulamalar su = uygulamaArray[r];
                   u_id = su.getUygulama_id();
                   f_id = su.getFirma_id();
                   f_isim = su.getFirma_ismi();
                   copyData(u_id, f_id, f_isim);
              Util.arrayCopy(result, (short)0, buffer, (short)0, res_index);
              result = null;
              short len = res_index;
              res_index = 00;
              apdu.setOutgoingAndSend((short)0, len);
         public void copyData(byte[] u_id, byte[] f_id, byte[] f_isim)
              Util.arrayCopy(u_id, (short)0, result, res_index, (short)u_id.length);
              res_index = (short)(res_index + u_id.length);
              Util.arrayCopy(f_id, (short)0, result, res_index, (short)f_id.length);
              res_index = (short)(res_index + f_id.length);
              Util.arrayCopy(f_isim, (short)0, result, res_index, (short)f_isim.length);
              res_index = (short)(res_index + f_isim.length);
              result[res_index] = (byte)0x7C;
              res_index = (short)(res_index + 1);
         public void copyData2(byte[] id, byte[] sehir, byte[] _banka)
              Util.arrayCopy(_id, (short)0, result2, res2_index, (short)_id.length);
              res2_index = (short)(res2_index + _id.length);
              Util.arrayCopy(_banka, (short)0, result2, res2_index, (short)_sehir.length);
              res2_index = (short)(res2_index + _sehir.length);
              Util.arrayCopy(_banka, (short)0,result2, res2_index, (short)_banka.length);
              res2_index = (short)(res2_index + _banka.length);
              result2[res2_index] = (byte)0x7C;
              res2_index = (short)(res2_index + 1);
         public void getFirmaIDFlag(byte[] f_id)
              for(short g = 0; g < index; g++)
                   SadakatUygulamalar su = uygulamaArray[g];
                   byte[] firma_no = su.getFirma_id();
                   if(equals(f_id, firma_no))
                        FirmaIDFlag = 1;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  

    Again, could you rewrite the createOdemeProfie() method code using TLV ??I guess you are referring to<tt> odemeCreateProfile </tt>in the original applet.
    I could* rewrite it in a cleaner way. But
    - Why should I* do that?
    - You did not give the spec of the applet and its APDU, and I'd hate to write code without specs, instead having to rely on the assumption that the original code is valid, which is dubious. For a tiny example, how could one guess if<tt> short lc = (short) buffer[ISO7816.OFFSET_LC]; </tt>is correct, or if rather the canonical<tt> short lc = (short)(buffer[ISO7816.OFFSET_LC]&0xFF); </tt>is required (that is, if the incoming data can exceed 127 bytes)?
    - the original sin lies in the design of new<tt> Odeme(_id, tarih, saat, firma, kategori, tutar, birim, ulke, sehir, ilce, aid, banka, taksit, _puan) </tt>needing so many explicit parameters.
    Without fixing the very definition of<tt> Odeme </tt>, the code will remain ugly. One possible design would be to have a method to set a field designated by its tag, and another to get the value of a field designated by its tag. Another design would be a method to set any number of fields passed as an array of bytes containing a concatenation of TLVs, and another to get any number of fields designated by an array of tag bytes, as an array of bytes containing a concatenation of the TLVs.
    Again, you* want to generalize what the code does until the nature of the data items manipulated never appear in a method or variable name, except as the name of a finalstatic variable (that is, as a constant), at least in utility methods like<tt> odemeCreateProfile </tt>, and in the constructor and accessors of <tt> Odeme </tt>. Think of it a building a tiny database engine, then using it. Of course when performing actual computation as opposed to mere data storage, it helps to name the variables, e.g. when adding a traveled distance to an odometer, or computing a cost from this or that per some formula (but beware that in Java Card, especially on platforms without<tt> int </tt>, straight formulas are seldom the right way to perform any but the simplest computations required in a real application).
    Edited by: fgrieu on Feb 8, 2013 11:46 AM

  • Testing java card applet

    Hi all,
    Am new to java card applet development. I have developed a sample applet. But i don't know how to test it. So can anyone help me understand this.
    please help.
    Thanks

    Hi,
    To test your application you need to install it on a Java Card virtual machine. This can either be on a real smartcard or in an emulator (such as the ones in the JCDK). When you have it installed you can then send APDU commands to exercise the applet. From memory, there is an example of how to use the CREF simulator in the JCDK Developer Guide that is a part of the package.
    If you have a real card, you can use something like GPShell to load and install your applet and to send commands to it. I have also found it is useful to have a host application written in Java (using jUnit) to test specific commands.
    - Shane

  • IDES for writing Java card applets and converting the applets as CAP FILE.

    I have developed a JAVA CARD APPLET , FindMFValueJCA.java . It gets compiles in net beans 6.0 But while converting the applet to CAP file i am getting some errors. Is there any other IDES which take care of converting the CAP files

    What's the Java version you are using?
    As the java card tool kit has version dependencies. If you are using java_card _kit 2.2.2 then 1.5 is fine.                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • How to open iPhoto in the new update ??

    Why can i no longer open iPhoto after the Yosemite update ?

  • Problems with regular Texting since iOS 7.0.3

    Hello, I have an iPhone 5s recently upgraded to iOS 7.0.3 via OTA update. I never use iMessage, I have an unlimited text plan, so I always have used SMS with everyone. However, after this last update, I have problems with regular SMS. I can send SMS

  • Synchronous data collection using pci-6143's

    I can set up synchronous data collection across the analog inputs of my three PCI-6143's using a separate task for each board and explicitly sharing the master timebase from board 1 (the one receiving the trigger to start data collection) to the othe

  • Imported files won't convert

    I'm trying to import some of my own audio files (mp3 and wav formats) but when I do so they supposedly 'import' but won't convert and drop into the timeline. Other files (such as those I've downloaded from iTunes) work fine. I need some ideas about w

  • Consolidation of 2 entity structures

    Hello Gurus I need helps pleace I have 2 entity structures. My problem is when I consolidate the other structure, get the status cn , which is without consolidate. SO I consolidate the first structure , the structure is set as consolidate. And I go t