Java Card without APDU

Hi,
during my practise with Java Card I'm finally able to write some applets. I did this the "classic" way. This means to install the .cap files using the APDU tool. But that is not really what I am looking for. I like to develop in the embedded sector and not smartcards. So my question is whether there is a way to use the Java Card VM without at least the APDU stuff. I found something about ROM applets. Are there still any APDU commands needed if I burn the applet in the ROM( any interface between user and applet isn't required (like PIN validation)). Or are there maybe other ways to avoid the installer.
thanks

then how will you do I/O with the card?
to verify a PIN, an apdu exchange is required.
do you want to code a library to be used by other applets? Just code it in java, put it in a cap, upload the cap. Then link the applet with the export file generated when you converted the library. ROM is not needed to write a library.
javacard by itself does no specify anything to allow rom access. To do this, you have to deal with the card manufacturer (gemalto, nxp, etc)
(And ROM is ROM, it cannot be burnt, it's made with a mask when the silicon chip is done.
Only EEPROM or OTP EPROM can be burned.)
Regards

Similar Messages

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

  • I cannot load my java card applet Response APDU: 69 85

    I know there have been many threads on this subject, I am a newbie to Java card development.
    Please someone help me.
    I am using the gpj for downloading the applet.
    The following is the output from the command "java -jar gpj.jar -load JCHelloWorld.cap -install"
    Thanks in advance
    run:
    Found terminals: [PC/SC terminal Generic PCSC Smartcard Reader 0]
    Found card in terminal: Generic PCSC Smartcard Reader 0
    ATR: 3B DB 96 00 80 B1 FE 45 1F 83 00 31 C0 64 C7 FC 10 00 01 90 00 74
    INFO: Selecting Security Domain OP201a, AID=A000000003000000
    DEBUG: Command APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
    DEBUG: Response APDU: 6F 6E 84 08 A0 00 00 00 03 00 00 00 A5 62 73 2F 06 07 2A 86 48 86 FC 6B 01 60 0C 06 0A 2A 86 48 86 FC 6B 02 02 01 01 63 09 06 07 2A 86 48 86 FC 6B 03 64 0B 06 09 2A 86 48 86 FC 6B 04 01 05 9F 6E 2A 48 20 50 2B 82 31 80 30 00 63 03 12 63 00 07 BB 03 00 11 42 12 97 11 43 12 97 11 44 12 97 01 00 00 00 00 00 00 00 00 00 00 00 9F 65 01 FF 90 00
    Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
    DEBUG: Command APDU: 80 50 00 00 08 FC 81 DB FE 80 72 19 28
    DEBUG: Response APDU: 00 00 03 12 63 00 07 BB 03 00 FF 01 DA 26 EF 49 10 B7 72 00 9A 24 7F B4 A0 1F C7 C8 90 00
    INFO: INITIALIZE UPDATE Successful
    DEBUG: Command APDU: 84 82 00 00 10 D5 41 CE BE F4 A8 E4 DD 36 6C C5 3E 19 9C 77 93
    DEBUG: Response APDU: 90 00
    DEBUG: Command APDU: 84 82 00 00 08 D5 41 CE BE F4 A8 E4 DD
    DEBUG: Response APDU: 90 00
    INFO: External Authentication Successful
    DEBUG: packagePath: com/samptah/card/javacard/
    DEBUG: package: com.samptah.card
    DEBUG: package AID: 9C 25 F6 5E AB 3F
    DEBUG: applet AIDs: [9C 25 F6 5E AB CD ]
    DEBUG: Command APDU: 80 E6 02 00 13 06 9C 25 F6 5E AB 3F 08 A0 00 00 00 03 00 00 00 00 00 00
    DEBUG: Response APDU: 00 90 00
    DEBUG: Command APDU: 80 E8 00 00 FF C4 82 01 4C 01 00 10 DE CA FF ED 01 02 04 00 01 06 9C 25 F6 5E AB 3F 02 00 1F 00 10 00 1F 00 0A 00 15 00 2E 00 0C 00 7F 00 18 00 12 00 00 00 6F 00 02 00 01 00 0B 02 01 00 04 00 15 02 04 01 07 A0 00 00 00 62 01 01 00 01 07 A0 00 00 00 62 00 01 03 00 0A 01 06 9C 25 F6 5E AB CD 00 08 06 00 0C 00 80 03 00 FF 00 07 01 00 00 00 1C 07 00 7F 00 01 10 18 8C 00 00 7A 05 30 8F 00 01 3D 8C 00 02 18 1D 04 41 18 1D 25 8B 00 03 7A 02 23 18 8B 00 04 60 03 7A 19 8B 00 05 2D 1A 03 25 11 00 FF 53 5B 32 1A 04 25 11 00 FF 53 5B 29 04 1F 10 80 6A 08 11 6E 00 8D 00 06 16 04 75 00 10 00 01 00 00 00 09 18 19 8C 00 07 70 08 11 6D 00 8D 00 06 7A 05 22 19 8B 00 05 2D 7B 00 08 92 32 7B 00 08 03 1A 03 1F 8D 00 09 3B 19 03 1F 8B 00 0A 7A 08 00 18 00 02 00 01 00 01 03 00 0B 48 65 6C 6C
    DEBUG: Response APDU: 69 85
    net.sourceforge.gpj.cardservices.exceptions.GPLoadException: Load failed, SW: 69 85
    at net.sourceforge.gpj.cardservices.GlobalPlatformService.loadCapFile(GlobalPlatformService.java:707)
    at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(GlobalPlatformService.java:1675)
    at gpj.Main.main(Main.java:26)
    BUILD SUCCESSFUL (total time: 1 second)

    Quite similar problem here. Here's what I got from GPShell:
    enable_trace
    establish_context
    card_connect
    select -AID a0000000030000
    Command --> 00A4040007A0000000030000
    Wrapped command --> 00A4040007A0000000030000
    Response <-- 6F658408A000000003000000A5599F6501FF9F6E06479181023100734A06072A864
    886FC6B01600C060A2A864886FC6B02020101630906072A864886FC6B03640B06092A864886FC6B0
    40215650B06092B8510864864020103660C060A2B060104012A026E01029000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4
    f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    Command --> 805000000804C1C46CBC9932AA00
    Wrapped command --> 805000000804C1C46CBC9932AA00
    Response <-- 000010700108859552580101AA4F3AEC5503E7A7435A0560E047AF489000
    Command --> 84820100100C2766279A1FC158181037B7A811AB93
    Wrapped command --> 84820100100C2766279A1FC158181037B7A811AB93
    Response <-- 9000
    delete -AID D0D1D2D3D4D50101
    Command --> 80E400000A4F08D0D1D2D3D4D5010100
    Wrapped command --> 84E40000124F08D0D1D2D3D4D501014018673D5E89975900
    Response <-- 6A88
    delete() returns 0x80206A88 (6A88: Referenced data not found.)
    delete -AID D0D1D2D3D4D501
    Command --> 80E40000094F07D0D1D2D3D4D50100
    Wrapped command --> 84E40000114F07D0D1D2D3D4D501887135A5C0B424D500
    Response <-- 6A88
    delete() returns 0x80206A88 (6A88: Referenced data not found.)
    delete -AID D0D1D2D3D4D50101
    Command --> 80E400000A4F08D0D1D2D3D4D5010100
    Wrapped command --> 84E40000124F08D0D1D2D3D4D501017144DF5DE0D2DE9F00
    Response <-- 6A88
    delete() returns 0x80206A88 (6A88: Referenced data not found.)
    install -file helloworld.cap -nvDataLimit 500 -instParam 00 -priv 2
    Command --> 80E602001907D0D1D2D3D4D50107A00000000300000006EF04C60201600000
    Wrapped command --> 84E602002107D0D1D2D3D4D50107A00000000300000006EF04C602016000
    C6EDAE8F91652A3B00
    Response <-- 6A88
    install_for_load() returns 0x80206A88 (6A88: Referenced data not found.)And this is what I've got from gpj
    Found terminals: [PC/SC terminal ACS ACR1281 1S Dual Reader ICC 0, PC/SC termina
    l ACS ACR1281 1S Dual Reader PICC 0, PC/SC terminal ACS ACR1281 1S Dual Reader S
    AM 0]
    Found card in terminal: ACS ACR1281 1S Dual Reader ICC 0
    ATR: 3B F8 18 00 00 81 31 FE 45 4A 43 4F 50 76 32 34 31 BC
    DEBUG: Command  APDU: 00 A4 04 00 07 A0 00 00 01 51 00 00
    DEBUG: Response APDU: 6A 82
    Failed to select Security Domain GP211 A0 00 00 01 51 00 00 , SW: 6A 82
    DEBUG: Command  APDU: 00 A4 04 00 08 A0 00 00 00 18 43 4D 00
    DEBUG: Response APDU: 6A 82
    Failed to select Security Domain GemaltoXpressPro A0 00 00 00 18 43 4D 00 , SW:
    6A 82
    DEBUG: Command  APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
    DEBUG: Response APDU: 6F 65 84 08 A0 00 00 00 03 00 00 00 A5 59 9F 65 01 FF 9F 6
    E 06 47 91 81 02 31 00 73 4A 06 07 2A 86 48 86 FC 6B 01 60 0C 06 0A 2A 86 48 86
    FC 6B 02 02 01 01 63 09 06 07 2A 86 48 86 FC 6B 03 64 0B 06 09 2A 86 48 86 FC 6B
    04 02 15 65 0B 06 09 2B 85 10 86 48 64 02 01 03 66 0C 06 0A 2B 06 01 04 01 2A 0
    2 6E 01 02 90 00
    Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
    DEBUG: Command  APDU: 80 50 00 00 08 A5 6A EB 5F E3 31 30 37
    DEBUG: Response APDU: 00 00 10 70 01 08 85 95 52 58 01 01 2E 43 22 1A A3 0A 65 4
    0 AA 8B D1 2A D5 89 8D 70 90 00
    DEBUG: Command  APDU: 84 82 00 00 10 B8 3A E1 AD 36 01 D8 E3 5F CC 77 B4 A7 F2 B
    E 68
    DEBUG: Response APDU: 90 00
    DEBUG: Command  APDU: 84 82 00 00 08 B8 3A E1 AD 36 01 D8 E3
    DEBUG: Response APDU: 90 00
    DEBUG: packagePath: com/tru/card/javacard/
    DEBUG: package: com.tru.card
    DEBUG: package AID: C3 79 3E 65 A1 00 EB F3 FD 20
    DEBUG: applet AIDs: [C3 79 3E 65 A1 C9 85 3B ]
    DEBUG: Command  APDU: 80 E6 02 00 17 0A C3 79 3E 65 A1 00 EB F3 FD 20 08 A0 00 0
    0 00 03 00 00 00 00 00 00
    DEBUG: Response APDU: 00 90 00
    DEBUG: Command  APDU: 80 E6 02 00 17 0A C3 79 3E 65 A1 00 EB F3 FD 20 08 A0 00 0
    0 00 03 00 00 00 00 00 00
    DEBUG: Response APDU: 00 90 00
    DEBUG: Command  APDU: 80 E8 00 00 FF C4 82 04 32 01 00 14 DE CA FF ED 01 02 04 0
    0 01 0A C3 79 3E 65 A1 00 EB F3 FD 20 02 00 1F 00 14 00 1F 00 0C 00 15 00 86 00
    12 02 CE 00 0A 00 53 00 00 00 F9 00 00 00 00 00 00 02 01 00 04 00 15 02 04 01 07
    A0 00 00 00 62 01 01 00 01 07 A0 00 00 00 62 00 01 03 00 0C 01 08 C3 79 3E 65 A
    1 C9 85 3B 00 01 06 00 12 00 80 03 0C 00 06 04 04 00 00 00 0C FF FF FF FF 01 27
    07 02 CE 00 02 30 8F 00 0C 3D 8C 00 0E 3B 7A 01 10 18 8C 00 0D AD 00 8B 00 0F 7A
    05 10 18 8C 00 10 18 10 08 88 01 18 11 3F 02 89 02 18 11 3F 03 89 03 18 11 3F 0
    4 89 04 18 11 3F 05 89 05 18 8B 00 1E 18 10 08 90 0B 3D 03 10 54 38 3D 04 10 52
    38 3D 05 10 55 38 3D 06 10 53 38 3D 07 10 4D 38 3D 08 10 41 38 3D 10 06 10 52 38
    3D 10 07 10 54 38 87 06 18 10 06 90 0B 3D 03 10 54 38 3D 04 10 53 38 3D 05 10 4
    3
    DEBUG: Response APDU: 6A 80
    DEBUG: Command  APDU: 80 E8 00 00 FF C4 82 04 32 01 00 14 DE CA FF ED 01 02 04 0
    0 01 0A C3 79 3E 65 A1 00 EB F3 FD 20 02 00 1F 00 14 00 1F 00 0C 00 15 00 86 00
    12 02 CE 00 0A 00 53 00 00 00 F9 00 00 00 00 00 00 02 01 00 04 00 15 02 04 01 07
    A0 00 00 00 62 01 01 00 01 07 A0 00 00 00 62 00 01 03 00 0C 01 08 C3 79 3E 65 A
    1 C9 85 3B 00 01 06 00 12 00 80 03 0C 00 06 04 04 00 00 00 0C FF FF FF FF 01 27
    07 02 CE 00 02 30 8F 00 0C 3D 8C 00 0E 3B 7A 01 10 18 8C 00 0D AD 00 8B 00 0F 7A
    05 10 18 8C 00 10 18 10 08 88 01 18 11 3F 02 89 02 18 11 3F 03 89 03 18 11 3F 0
    4 89 04 18 11 3F 05 89 05 18 8B 00 1E 18 10 08 90 0B 3D 03 10 54 38 3D 04 10 52
    38 3D 05 10 55 38 3D 06 10 53 38 3D 07 10 4D 38 3D 08 10 41 38 3D 10 06 10 52 38
    3D 10 07 10 54 38 87 06 18 10 06 90 0B 3D 03 10 54 38 3D 04 10 53 38 3D 05 10 4
    3
    DEBUG: Response APDU: 6A 80
    net.sourceforge.gpj.cardservices.exceptions.GPLoadException: Load failed, SW: 6A
    80
            at net.sourceforge.gpj.cardservices.GlobalPlatformService.loadCapFile(Un
    known Source)
            at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S
    ource)
    javax.smartcardio.CardNotPresentException: No card present
            at sun.security.smartcardio.TerminalImpl.connect(Unknown Source)
            at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S
    ource)
    Caused by: sun.security.smartcardio.PCSCException: SCARD_W_REMOVED_CARD
            at sun.security.smartcardio.PCSC.SCardConnect(Native Method)
            at sun.security.smartcardio.CardImpl.<init>(Unknown Source)
            ... 2 more
    Found card in terminal: ACS ACR1281 1S Dual Reader PICC 0
    java.lang.NullPointerException
            at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S
    ource)
    javax.smartcardio.CardNotPresentException: No card present
            at sun.security.smartcardio.TerminalImpl.connect(Unknown Source)
            at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S
    ource)
    Caused by: sun.security.smartcardio.PCSCException: SCARD_W_REMOVED_CARD
            at sun.security.smartcardio.PCSC.SCardConnect(Native Method)
            at sun.security.smartcardio.CardImpl.<init>(Unknown Source)
            ... 2 more
    Found card in terminal: ACS ACR1281 1S Dual Reader SAM 0
    java.lang.NullPointerException
            at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown S
    ource)What can I do to fix this? Did I missed any steps? Thanks for any reply.

  • Does java card support PIN encryption on APDU Verify Command???

    hello
    I want to know if java card allows PIN encryption in the APDU verify command? because such an action necessits that a section key has to be set between the server (SC applet) and the client application.
    thanks a lot

    Many Java cards support the GlobalPlatform Open Platform specification
    which can be downloaded for free from http://www.globalplatform.org .
    This specification contains a mechanism called "secure messaging".
    All APDUs sent to applications or the cardmanager and the corresonding
    responses can be enrypted when using secure messaging.
    In order to use secure messaging a "mutual authentication" is necessary
    where the off-card entity authenticates itself to an application,
    e.g. the card manager, and the application authenticates itself to the
    off-card entity.
    Naturally, this involves static keys on/off-card and session keys.

  • Java Card APDU's

    Hello,
    I'm new to Java Card and I'm having trouble getting started. I installed the Java Card plugin into Eclipse and I also set up Netbeans with the plugins as well. I know how to convert the java file into a .cap file and from there into a script. In Eclipse I'm successful in running the script with the CREF but I don't really know how to work with the output. When working with Java I can fix my programs by seeing what's happening but I can't do that with Java Card. In Netbeans I saw that you can send APDU commands to their Default Device. Is there somewhere I can go to find out what commands to send to it to interact with my applet?
    I want to understand how this works before putting a cap file on a smart card...or is that the only way to test it?

    You can also use OpenCard Framework (OCF) to communicate with the CREF emulator from a host application. You should be able to search the forum for related posts for details.
    It is a very good idea to test against an emulator when developing as it is faster and may allow you to debug your code as well. Just remember that the CREF and JCWDE emulators have limitations. These are described in the documentation that ships with the JCDK.
    Cheers
    Shane

  • Please ..give me some example APDU for writing data to java card

    morning everybody .. :)
    I need some example APDUs for writing data to java card. (CLA || INS || P1 || P2 etc)..
    please..thank for your attention .. god blessing u.

    Hi,
    did you check some articles about JavaCards:
    [Understanding Java Card 2.0|http://www.javaworld.com/cgi-bin/mailto/x_java.cgi?pagetosend=/export/home/httpd/javaworld/javaworld/jw-03-1998/jw-03-javadev.html&pagename=/javaworld/jw-03-1998/jw-03-javadev.html&pageurl=http://www.javaworld.com/javaworld/jw-03-1998/jw-03-javadev.html&site=jw_core]
    [How to write a Java Card applet: A developer's guide|http://www.javaworld.com/cgi-bin/mailto/x_java.cgi?pagetosend=/export/home/httpd/javaworld/javaworld/jw-07-1999/jw-07-javacard.html&pagename=/javaworld/jw-07-1999/jw-07-javacard.html&pageurl=http://www.javaworld.com/javaworld/jw-07-1999/jw-07-javacard.html&site=jw_core]
    Hope it helps,
    Tex

  • Problem Installing the loaded applet in Samsung java card (S3CC9P9).

    Hi all,
    Am trying to install the applets already loaded into the Samsung java card(S3CC9P9), because am unable to select the applet which are loaded into the card. I got to know that the applets are only loaded, they are not installed in the card, without installing the applet ,we cannot select the applet. Am using gpj(version 20120310 ) to install the applets into the card.
    When i execute : java -jar gpj.jar -list
    i get the list of applets in the card as :
    AID: A0 00 00 00 03 00 00 00 |........| ISD LC: 1 PR: 0x1A
    AID: A0 00 00 00 03 10 |......| Exe LC: 1 PR: 0x00
    AID: D4 10 65 09 90 00 10 00 |..e.....| Exe LC: 1 PR: 0x00
    AID: 31 50 41 59 2E |1PAY.| Exe LC: 1 PR: 0x00
    AID: D4 10 65 09 90 00 30 00 |..e...0.| Exe LC: 1 PR: 0x00
    AID: D4 10 65 09 90 00 20 00 |..e... .| Exe LC: 1 PR: 0x00
    Here am able to select only the first applet i.e., A0 00 00 00 03 00 00 00
    SO, when i try to install the other applets, for example A0 00 00 00 03 10, its fails.
    When i execute : java -jar gpj.jar -install -applet A00000000310
    i get :
    Found terminals: [PC/SC terminal ACS ACR38U 00 00]
    Found card in terminal: ACS ACR38U 00 00
    ATR: 3B 69 00 00 80 63 31 46 DF 83 FF 90 00
    DEBUG: Command APDU: 00 A4 04 00 07 A0 00 00 01 51 00 00
    DEBUG: Response APDU: 6A 82
    Failed to select Security Domain GP211 A0 00 00 01 51 00 00 , SW: 6A 82
    DEBUG: Command APDU: 00 A4 04 00 08 A0 00 00 00 18 43 4D 00
    DEBUG: Response APDU: 6A 82
    Failed to select Security Domain GemaltoXpressPro A0 00 00 00 18 43 4D 00 , SW: 6A 82
    DEBUG: Command APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
    DEBUG: Response APDU: 6F 19 84 08 A0 00 00 00 03 00 00 00 A5 0D 9F 6E 06 10 01 76 DE 00 05 9F 65 01 7F 90 00
    Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
    DEBUG: Command APDU: 80 50 00 00 08 AE 2A B8 CE 3A BB E0 B0
    DEBUG: Response APDU: 00 00 61 41 01 09 38 2F 09 5A FF 01 3F D9 93 D9 FE 9A FA 3B E4 B7 21 89 6A 34 AB 18 90 00
    DEBUG: Command APDU: 84 82 00 00 10 A2 63 07 96 0B D8 A3 A9 93 A2 5C 7C 6D B7 E0 54
    DEBUG: Response APDU: 90 00
    DEBUG: Command APDU: 84 82 00 00 08 A2 63 07 96 0B D8 A3 A9
    DEBUG: Response APDU: 90 00
    java.lang.NullPointerException
         at net.sourceforge.gpj.cardservices.GlobalPlatformService.installAndMakeSelecatable(Unknown Source)
         at net.sourceforge.gpj.cardservices.GlobalPlatformService.main(Unknown Source)
    Can anyone please tell me where am wrong and how to make the applets selectable.
    Thanks in advance

    hy
    1. do you have a reader with a serial (com1) connection?
    if so, the reader has to be connected before starting windows. so windows recognizes it.
    2. have a look to the control panel. is there a tool - installed during driver installation - to test and configure the reader?
    if so try it.
    if all that works, the jcop tools communicate with the reader over the installed driver.
    snoopy

  • Manually upload .cap file on a java card

    Hi
    I wonder how to manually upload a .cap file on a java card. I do know that it must be an or more APDUs that contain the file and so on.
    What I wonder is how to convert a .cap file into a byte array (byte array that on-card installer can read and understand) without using JCOP or any other tools? Does (must) this array have a special format or something?
    I am interested in the process of taking a.cap file and convert it to byte array (nothing else).
    Thanks in advance!
    /Lyudmila

    The .cap file uploading mechanism depends if you have a java card or a GlobalPlatform card.Java Card cards are GlobalPlatform based.
    If you have a java card you can use the same mechanism that it is used with Cref (see Java Card Kit - Development Kit - Chapter 11): .cap file is divided in n apdus, one or more (if a component not fit in one apdu, for example method component) for component (first:Header.cap, second:directory.cap, third:import.cap, etc).
    If you use a GlobalPlatform card, the mechanism is more complex:
    first you have to create a session using a specific protocol (SCP01, SCP02, etc) through INITIALIZE UPDATE and EXTERNAL AUTHENTICATE commands, then an INSTALL FOR LOAD command and n LOAD commads as they are necessary.
    To use GlobalPlatform mechanism, see GlobalPlatform Specification 2.1.1.The JCRE spec does not define the applet loader and CREF has a basic version of an applet loader that is not GP compliant, but this is not the Java Card standard. To load onto any physical Java Card you will need to follow the GlobalPlatform specification.
    - Shane

  • How to initial pin number of java card by user

    Hello,
    I want to create Android Mobile Payment application using Java Card. I find the example and tutorial from the internet and I found the Java Card Applet Developer’s Guide and another example. After I read those files and examples, Most of them set pin with assign the fixed value into the code. So, I want to know there is any way to set the pin code by user dynamically.
    Moreover, I have one more question. I would like to store the credit card information into secure element on Android Phone. Which APDU command do I need to use ? WRITE BINARY or WRITE RECORD?

    Yes - the javascript will provide a quick response to the user without having to go to the server. However its probably a good idea to have a validation in the validation section that validates it before you insert/update/etc. People can turn off javascript in the browser, so a page validation is always a good idea - Now the reality is the way Apex is built a user can't really turn off javascript because most of the buttons invoke javascript to submit the page, but thats another story.
    You would code your button to do a URL redirect instead of submit if you want to use the javascript. Like:
    javascript:submit();Now I hardcoded a doSubmit('SUBMIT') which is what your button would do, but if you need different request values, you can make it a variable and do it like that:
    javascript:submit('CREATE');
    function submit(pRequest){
      if(check()){
        doSubmit(pRequest);
    }The Oracle side would be something more like this (just pseudocode - read up on the utility packages):
      v_table := apex_util.string_to_table(:P1_SHUTTLE);
      if v_table.count > 10 then
        return(false);
      else
        return(true);
      end if;Arggg - meant string_to_table - not list_to_table

  • 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

  • How to check the output of a java card program ?

    Hi,
    I am new to java card technology.I am trying to run a simple helloworld program given in the java development kit2.2 -windows samples in eclipse3.5.
    For running I followed the following steps:-
    1) Firstly,I went to JCWDE->start
    2) then on Project->java tools->deploy
    It shows me following output :-
    Java Card 2.2.2 APDU Tool, Version 1.3
    Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
    Opening connection to localhost on port 9025.
    Connected.
    Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
    CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 08, 01, Le: 00, SW1: 90, SW2: 00
    CLA: 80, INS: b0, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00
    CLA: 80, INS: b2, P1: 01, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00
    CLA: 80, INS: b4, P1: 01, P2: 00, Lc: 18, 01, 00, 15, de, ca, ff, ed, 01, 02, 04, 00, 01, 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 01, Le: 00, SW1: 64, SW2: 3a
    CLA: 80, INS: bc, P1: 01, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b2, P1: 02, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 02, P2: 00, Lc: 20, 02, 00, 1f, 00, 15, 00, 1f, 00, 0f, 00, 15, 00, 36, 00, 0c, 00, 69, 00, 0a, 00, 14, 00, 00, 00, 6c, 00, 00, 00, 00, 00, 00, 02, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 02, P2: 00, Lc: 02, 01, 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: bc, P1: 02, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b2, P1: 04, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 04, P2: 00, Lc: 18, 04, 00, 15, 02, 03, 01, 07, a0, 00, 00, 00, 62, 01, 01, 00, 01, 07, a0, 00, 00, 00, 62, 00, 01, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: bc, P1: 04, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b2, P1: 03, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 03, P2: 00, Lc: 12, 03, 00, 0f, 01, 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 00, 00, 14, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: bc, P1: 03, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b2, P1: 06, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 06, P2: 00, Lc: 0f, 06, 00, 0c, 00, 80, 03, 01, 00, 01, 07, 01, 00, 00, 00, 21, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: bc, P1: 06, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b2, P1: 07, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 07, 00, 69, 00, 02, 10, 18, 8c, 00, 01, 18, 11, 01, 00, 90, 0b, 87, 00, 18, 8b, 00, 02, 7a, 02, 30, 8f, 00, 03, 3d, 8c, 00, 04, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 8b, 00, 02, 7a, 05, 23, 19, 8b, 00, 05, 2d, 19, 8b, 00, 06, 32, 03, 29, 04, 70, 19, 1a, 08, ad, 00, 16, 04, 1f, 8d, 00, 0b, 3b, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 16, 04, 1f, 41, 29, 04, 19, 08, 8b, 00, 0c, 32, 1f, 64, e8, 19, 8b, 00, 07, 3b, 19, 16, 04, 08, 41, 8b, 00, 08, 19, 03, 08, 8b, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 0c, 00, 09, 19, ad, 00, 03, 16, 04, 8b, 00, 0a, 7a, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: bc, P1: 07, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b2, P1: 08, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 08, P2: 00, Lc: 0d, 08, 00, 0a, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: bc, P1: 08, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b2, P1: 05, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 20, 05, 00, 36, 00, 0d, 02, 00, 00, 00, 06, 80, 03, 00, 03, 80, 03, 01, 01, 00, 00, 00, 06, 00, 00, 01, 03, 80, 0a, 01, 03, 80, 0a, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 19, 06, 03, 80, 0a, 07, 03, 80, 0a, 09, 03, 80, 0a, 04, 03, 80, 0a, 05, 06, 80, 10, 02, 03, 80, 0a, 03, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: bc, P1: 05, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b2, P1: 09, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: b4, P1: 09, P2: 00, Lc: 17, 09, 00, 14, 00, 03, 0e, 27, 2c, 00, 0d, 05, 0c, 06, 04, 03, 07, 05, 10, 0c, 08, 09, 06, 09, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: bc, P1: 09, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    CLA: 80, INS: ba, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 21
    Can anyone tell me what is this output? And Am i deplyoing in the right way?

    Hi,
    You might want to check the JCDK user guide (cJDK_Users_Guide_bin_do.pdf) for details of using an emulated card environment. It outlines how to use the simulators provided with the JCDK. This should tell you how the deploy process works and will give you some insight into what this script is doing.
    Cheers,
    Shane

  • Need some OO design pointers for a Java card game I wrote for uni

    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
         private int value;                    //variable for the value of the card
         private int suit;                         //variable for the suit of the card
         private ImageIcon frontOfCard;     //Displays the image of the front of the cards
         private ImageIcon backOfCard;          //displays the image of the back of the cards
         public Card (int Value, int Suit, ImageIcon front, ImageIcon back)
              value = Value;               
              suit = Suit;               
              frontOfCard = front;     
              backOfCard = back;
              setIcon(backOfCard);     //To make it non-visible when dealt
         }As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    Card class
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instance
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.
    AI Class extends Player Class
    GUI Class
    Deck Class <-- contains 52 cards
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    Any help on this would be greatly appreciated!
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.

    Faz_86 wrote:
    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    Admirable, and the best way to learn, doing something that interests you.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    Do a quick Google on the model view controller pattern. Your listeners are your controllers. Your JPanel, JButton, etc. are your view. The AI, Player, Card and Deck (and presumably something like Score) are your model. Your model should be completely testable and not dependent on either the controller or the view. Imagine you could play the game from the command line. Get that working first. Then you can add all the bells and whistles for the UI.
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
    (redacted)
    As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.Extending JPanel is fine. As you noted, you need something to add listeners to. However, I would separate things a bit. First, a card really only has a rank and suit (and perhaps an association to either the deck or a player holding the card). The notion of setIcon() is where you are tripping up. The card itself exists in memory. You should be able to test a card without using a UI. Create a separate class (CardPanel or something similar) that has a reference to a Card and the additional methods needed for your UI.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    I am not an animation buff, so I will assume the above works.
    Card classRemove the UI aspects to this class, and I think you are all set here.
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instancePresumably this is where main() resides. It will certainly have a reference to model classes (player, game, deck, etc.) and likely the master JFrame (or a controller class you create yourself).
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.Does a player really have multiple hands? It seems to me more of a one-to-one relationship (or a player has a one-to-many relationship to Card).
    AI Class extends Player ClassWhy extend Player? Create a Player interface, then have a HumanPlayer and AIPlayer implementation. Common parts could be refactored out into either a helper class (delegation) or AbstractPlayer (inheritance).
    GUI ClassMy assumption is that this class has a reference to the master JFrame.
    Deck Class <-- contains 52 cards
    Yes. You may end up recycling this class such that a Deck can also function as a Hand for a given player. If there are differences between the two, create an interface and have a Hand and a Deck implementation. Coding to interfaces is a good thing.
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?You need to pass a reference to the appropriate view class. That is how MVC works. The controller receives a request from the view, dispatches to some model functionality you write (such as GameRulesEngine, Deck, etc.) and returns a result to the view (which could be the same view or a different one, imagine someone clicking 'high scores').
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    That is up to you to write the animation code. In principle, you have a mouse listener, and then you take the appropriate rendering steps.
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    See above.
    Any help on this would be greatly appreciated!
    You are welcome.
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.No, you have been doing fine.
    - 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

  • Java card query

    I am a student in my final year of university and im looking into using the java card as part of my final project. could somebody clarify for me some things i am unsure of. Am i able to use any smart card reader or do i need one specific for a java card, if so which one. If i can use any im ok as i can get hold of some. Also, am i correct in that i would write my java code as normal then use a program to write it to the card? any help would be much appreciated. Thanks

    Hi,
    you can use any reader.
    the java code has to be compiled , then converted using the sun-provided JCDK tool "converter" then loaded in the card using globalplatform, with the gpshell tool.
    beware, there are some restrictions to what can be written in the code. specifically, there is no "int" "float" "java.lang.String" and the memory is very small.
    and yes, objects are allocated in non volatile memory. So the "new" keyword must not be used too often, except in the initialization methods.
    why? because the JC virtual machine is always live. it does not stop. When you tear the card, the VM is suspended, then resumed when you reinsert the card, but the objects are still here.
    when an apdu is sent to the card, the JCVM calls a callback in your code. But your Applet object still exists.
    regards
    sebastien.

Maybe you are looking for

  • Ipod Nano 6th gen USB problem with JBL 1000 Radio

    My Ipod nano 6th generation will nt sync to my JBL Radio sytem through the USB Port. I am trying to download music from my Ipod to the hard drive on my JBL Radio. I have done this before with a different name brand player through the USB Port. The Na

  • Gamma levels on MacMini/Mountain Lion

    I have migrated my FCP 7 over to a MacMini, upgrading the OS to 10.8 in the process.  The first time, I just used my time machine to copy to the new computer, but all may Final Cut Material showed up with significantly altered gamma levels.  I had to

  • I want to buy a song off the US store

    I've been after a song for ages but the UK iTunes doesnt have it but the US iTunes does but I've tried buying it off there and am not allowed is there any way to buy the song through the UK site

  • Cancelling Inspection Lots - In Process Lots 03 origin

    Hi, I have recently deployed the QM module of ECC 6 to interact with a LIMS system via QM-IDI interface as part of an overall ECC 6 implementation. I generate inspection lots in the following scenarios: 1. Goods Receipt from Purchase Orders 2. In pro

  • Macbook Pro won't go past gray apple screen

    When I turn my macbook on, it makes the chime and the gray apple screen appears.  Then a progress bar appears and after it is finished loading, there is just a spinning loading circle thingy under the apple. My laptop never goes past this screen, it