How do I test a Java card applet with different AIDs on the fly?

... Like sweeping cards from employees in a queue of people lining up in the morning?
When I created my applet, the aid is a fixed value inside the class.
Whenever I wanted to test it with another value, I changed that AID and rerun the applet.
I find it very cumbersome that needs to be rerun and rerun, over and over again.
How do I test the applet easily with any values of AIDs that I'd like to put in, on the fly.
I know I can't simulate the sweeps of card in the applet because I can't have a main method with a signature
of Strings[] args or String[] args. I can only have JUnit to help me out, but still java card doesn't allow either
main(Strings[] args) or TestCase to inherit from.
Thanks
Jack

your question is hard to understand but:
an applet always has one definite AID and you cant change it after install as far as i know
a) you want to test many cards with diffrent AIDs?
->send a list of select commands and check the return values
b)you want one card with the same applet to be available for many AIDs?
->install many dummy applets forwarding the commands to one core applet
c)i think i didnt get your point :/

Similar Messages

  • How do I communicate a Java Card applet with a server?

    I'm new to Java and Java Card and currently developing a smart card system. I'm not sure what to use on my applet or server, JCSystem or SecureConnection or something else?
    If I'm writing a server application, then how do I install it so that I can simulate it with cjre?
    Thanks in advance.
    p/s: Connection is using TSL.

    The flow is like this:
    Java Card --> POS terminal -> Server
    Yes. I'm using JC3.
    Here's what I've achieved so far using SocketConnection
    SocketConnection sc = (SocketConnection) Connector.open("socket://localhost:50007");
    InputStream is = sc.openInputStream();
    OutputStream os = sc.openOutputStream();
    os.write("Hello world!".getBytes());
    is.read(buffer);
    os.close();
    is.close();
    sc.close(); Edited by: andirady on Dec 4, 2012 11:59 PM

  • 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

  • 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

  • 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

  • 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

  • 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.

  • 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.                                                                                                                                                                                                                                                                                                   

  • How do you test your Java Pricing UserExits in eclipse?

    How do you test your Java Pricing UserExits in eclipse?

    do you have to deploy the java class on vmc server to debug it
    Yes
    - So, the classes have to be compiled error free and uploaded to VMC.
    - VMC has to be restarted to test your classes.
    - You have to set the log levels appropriately for your classes using SM53 / SM52.
    -  You can also perform VMC debug through Eclipse.
    all of the details are available in the pricing exit manual*

  • 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 debugging in Netbeans 6.8

    Hi,
    | am writing a Java Card applet and a client MIDlet. I would like to debug my applet: I want to see the interaction process with MIDlet. However, for some reason I cannot start debugging in Netbeans 6.8. Could someone help? Thanks in advance.
    Regards,
    Aleksandr

    Hi sanyas,
    sorry, i'm not answering your question..
    I'm a newbie in Java Card technology..
    After i had read your post, it makes me curious about Java Card Client..
    I want to know, what kind of Java Card Client that we could create?..
    Can we create a Java Card client application from Java SE (GUI/Swing base application), or it's limited for MIDlet only?
    Thanks in advance..

  • Java card Applet and sim toolkit applet

    What is Difference between this two?
    When i load java card applet on sim ,then applet is not visible on GSM phone. But sim toolkit Applet is visible on GSM phone.
    i think,SIM uses sim.toolkit ad sim.access to interact with Applet.
    is it so?
    Plz solve my query.
    Thankx 4 ur valuable time.
    Regards
    Divyesh.

    for programming in sim card, you must use necessarily sim toolkit applet.
    I thing that the difference between Javacard applet and Simtoolkit applet is that:
    - sim toolkit applet is only for sim card
    - java card applet is for another smart card
    of course, both have some joint things.

  • Firewall - Java Card project with two packages.

    My Java Card project has got two Java Card packages. One of them contains only the Java Card applet. The other package contains all other classes. We did the splitting because our application is large and if all the code is left inside the one package if debug mode was checked, the size of the cap file was more than 64 bytes and the CAP file with that size cannot be installed inside the simulator. That situation made the programming difficult. Therefore the splitting took place. What is my question? If we have two packages, is there a firewall between them or the packages are in the same group context.

    A library package has different restrictions to an applet package. As for the firewall, the data created in your library package is owned by the applet instance that created it. That means any data or objects created by calling your library from your applet will be in the same context as your applet. Any other applet accessing this library will not be able to access instances from the original context. This is only a problem with static fields and methods etc that are shared between both applets.
    Cheers,
    Shane

  • I can't redeem my iTunes gift card, my phone is un activated, help desk has not helped. What does it mean my phone is un activated and how can I redeem my gift card for my 5c living I. The Caribbean

    I can't redeem my iTunes gift card, my phone is un activated, help desk has not helped. What does it mean my phone is un activated and how can I redeem my gift card for my 5c living I. The Caribbean

    (Typing all in capitals is considered shouting, makes posts difficult to read and may mean that people are less likely to reply.)
    There isn't a phone number for iTunes Support.
    If you've forgotten your answers to your security questions then you can get them reset : If you forgot the answers to your Apple ID security questions
    If you have a credit card on your account then its details have to complete - and asking for their details is also a way of checking that you have a valid billing address in that country. As long as you are buying content for yourself and not trying to gift content (you can't use your balance for gifting) then the purchase price (plus any applicable taxes) should be deducted from your balance. If it's not then you contact iTunes Support :  http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

Maybe you are looking for

  • FATAL ERROR occurred during installation

    Trying to install a HP Officejet 4500 G510g-m onto a HP Desktop PC with Windows Vista. Error message reads: Fatal error message during installation An error occurred during installation of assembly 'Microsoft.vc90.MFC,version="9.0.21022.8",publickeyt

  • Javax.naming.NameNotFoundException during a lookup() call.

    I am getting this exception when I try to get a reference to my Local Entity bean from within a Remote Session bean. ( I did a search in these forums, and found a few topics similar to mine. However, those that were similar were unfortunately still u

  • Itunes thinks i'm not connected to the internet.

    I keep trying to update to 1.2, but every time i try, it says i'm not connected to the internet. Itunes Store works fine, and I have a cable modem. I've tried turning off my firewall, re-installing. These are the results of the itunes network diagnos

  • How the **** do I reinstall Mail??

    Hi there... I wan't to reinstall Mail and I've inserted my original 10.5 Leopard install-DVD, but when I try to install Mail using "optional installs" it's not possible to check the box next to "Mail" - it's gray and "non-active" I'm loged in as admi

  • HT1176 Initial Time Capsule backup on MacBook Pro that doesn't have an Ethernet port

    I just got a 3TB time capsule and am trying to backup my MacBook Pro. The initial process is very slow, but my MacBook doesn't have an Ethernet port. How can I connect the time capsule to the MacBook Pro to make the initial backup go more quickly?