Javacard apdu

Hi you all,
I'm trying to run the apdutool.
I first had the
"Exception in thread 'main' java.lang.NoClassDefFoundError: javax/comm/PortInUseException" message and I tried then to install the comm api to fix this.
But since I've added comm.jar to my classpath, I get an application error message from java.exe saying:
"The memory could not be 'read' " when running apdutool.
Worst, it seems like converter is crashing for the same reason as well since then.
I suspect that while I'm running it with JDK 1.4, some troubles might appear.
Is there anybody to confirm it or help me to work that out ??
Thanks in advance

Yes it is.
I've found a work around to that.
What I do is compiling everything without adding comm.jar to the environment and from another command prompt then run the apdutool.
It seems ok this way. Everything is still not clear to what happens but at least I managed to simulate my javacard applet.

Similar Messages

  • What is the mean of : Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00?

    Hi Friends..
    I tried to open two consoles in windows..
    the first console is used to run cref
    the second console is usde to run apdutool
    I tried to run the script for HelloWorld.cap and wallet.cap that generated by scriptgen ..
    but i always got this return : Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
    C:\java_card_kit-2_2_1\samples\src\com\sun\javacard\samples\wallet\javacard>apdu
    tool test.txt
    Java Card 2.2.1 APDU Tool, Version 1.3
    Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to lic
    ense terms.
    Opening connection to localhost on port 9025.
    Connected.
    Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00What's the mean of this?
    Thanks in advance..

    Hi safarmer..
    this is the content of test.txt :
    powerup;
    0x80 0xB0 0x00 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/Header.cap
    0x80 0xB2 0x01 0x00 0x00 0x7F;
    0x80 0xB4 0x01 0x00 0x16 0x01 0x00 0x13 0xDE 0xCA 0xFF 0xED 0x01 0x02 0x04 0x00 0x01 0x09 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x06 0x7F;
    0x80 0xBC 0x01 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/Directory.cap
    0x80 0xB2 0x02 0x00 0x00 0x7F;
    0x80 0xB4 0x02 0x00 0x20 0x02 0x00 0x1F 0x00 0x13 0x00 0x1F 0x00 0x0E 0x00 0x0B 0x00 0x5E 0x00 0x12 0x01 0xCD 0x00 0x0A 0x00 0x3A 0x00 0x00 0x00 0xD4 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x7F;
    0x80 0xB4 0x02 0x00 0x02 0x01 0x00 0x7F;
    0x80 0xBC 0x02 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/Import.cap
    0x80 0xB2 0x04 0x00 0x00 0x7F;
    0x80 0xB4 0x04 0x00 0x0E 0x04 0x00 0x0B 0x01 0x02 0x01 0x07 0xA0 0x00 0x00 0x00 0x62 0x01 0x01 0x7F;
    0x80 0xBC 0x04 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/Applet.cap
    0x80 0xB2 0x03 0x00 0x00 0x7F;
    0x80 0xB4 0x03 0x00 0x11 0x03 0x00 0x0E 0x01 0x0A 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x06 0x01 0x00 0x41 0x7F;
    0x80 0xBC 0x03 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/Class.cap
    0x80 0xB2 0x06 0x00 0x00 0x7F;
    0x80 0xB4 0x06 0x00 0x15 0x06 0x00 0x12 0x00 0x80 0x03 0x02 0x00 0x01 0x04 0x04 0x00 0x00 0x00 0x5C 0xFF 0xFF 0x00 0x4F 0x00 0x64 0x7F;
    0x80 0xBC 0x06 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/Method.cap
    0x80 0xB2 0x07 0x00 0x00 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x07 0x01 0xCD 0x00 0x05 0x43 0x18 0x8C 0x00 0x03 0x18 0x8F 0x00 0x12 0x3D 0x06 0x10 0x08 0x8C 0x00 0x02 0x87 0x00 0x19 0x1E 0x25 0x29 0x04 0x1E 0x16 0x04 0x41 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x04 0x41 0x31 0x19 0x1E 0x25 0x29 0x05 0x1E 0x16 0x05 0x41 0x04 0x41 0x31 0x19 0x1E 0x25 0x29 0x06 0xAD 0x00 0x19 0x1E 0x04 0x41 0x16 0x06 0x8B 0x00 0x04 0x18 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x8B 0x00 0x05 0x7A 0x05 0x30 0x8F 0x00 0x06 0x3D 0x18 0x1D 0x1E 0x8C 0x00 0x07 0x3B 0x7A 0x01 0x10 0xAD 0x00 0x8B 0x00 0x08 0x61 0x04 0x03 0x78 0x04 0x78 0x01 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x10 0xAD 0x00 0x8B 0x00 0x09 0x7A 0x04 0x21 0x19 0x8B 0x00 0x0A 0x2D 0x1A 0x03 0x1A 0x03 0x25 0x10 0xFC 0x53 0x38 0x1A 0x03 0x25 0x61 0x0A 0x1A 0x04 0x25 0x10 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0xA4 0x6B 0x03 0x7A 0x1A 0x03 0x25 0x10 0x80 0x6A 0x08 0x11 0x6E 0x00 0x8D 0x00 0x0B 0x1A 0x04 0x25 0x75 0x00 0x2D 0x00 0x04 0x00 0x20 0x00 0x27 0x00 0x30 0x00 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x21 0x00 0x40 0x00 0x1B 0x00 0x50 0x00 0x15 0x18 0x19 0x8C 0x00 0x0C 0x7A 0x18 0x19 0x8C 0x00 0x0D 0x7A 0x18 0x19 0x8C 0x00 0x0E 0x7A 0x18 0x19 0x8C 0x00 0x0F 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x7A 0x11 0x6D 0x00 0x8D 0x00 0x0B 0x7A 0x03 0x24 0xAD 0x00 0x8B 0x00 0x10 0x61 0x08 0x11 0x63 0x01 0x8D 0x00 0x0B 0x19 0x8B 0x00 0x0A 0x2D 0x1A 0x07 0x25 0x32 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x19 0x8B 0x00 0x11 0x5B 0x29 0x04 0x1F 0x04 0x6B 0x07 0x16 0x04 0x04 0x6A 0x08 0x11 0x67 0x00 0x8D 0x00 0x0B 0x1A 0x08 0x25 0x29 0x05 0x16 0x05 0x10 0x7F 0x6E 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x06 0x16 0x05 0x63 0x08 0x11 0x6A 0x83 0x8D 0x00 0x0B 0xAF 0x01 0x16 0x05 0x41 0x11 0x7F 0xFF 0x6F 0x08 0x11 0x6A 0x84 0x8D 0x00 0x0B 0x18 0xAF 0x01 0x16 0x05 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x41 0x89 0x01 0x7A 0x03 0x24 0xAD 0x00 0x8B 0x00 0x10 0x61 0x08 0x11 0x63 0x01 0x8D 0x00 0x0B 0x19 0x8B 0x00 0x0A 0x2D 0x1A 0x07 0x25 0x32 0x19 0x8B 0x00 0x11 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x5B 0x29 0x04 0x1F 0x04 0x6B 0x07 0x16 0x04 0x04 0x6A 0x08 0x11 0x67 0x00 0x8D 0x00 0x0B 0x1A 0x08 0x25 0x29 0x05 0x16 0x05 0x10 0x7F 0x6E 0x06 0x16 0x05 0x63 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x08 0x11 0x6A 0x83 0x8D 0x00 0x0B 0xAF 0x01 0x16 0x05 0x43 0x63 0x08 0x11 0x6A 0x85 0x8D 0x00 0x0B 0x18 0xAF 0x01 0x16 0x05 0x43 0x89 0x01 0x7A 0x04 0x22 0x19 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x8B 0x00 0x0A 0x2D 0x19 0x8B 0x00 0x13 0x32 0x1F 0x05 0x6D 0x08 0x11 0x67 0x00 0x8D 0x00 0x0B 0x19 0x05 0x8B 0x00 0x14 0x1A 0x03 0xAF 0x01 0x10 0x08 0x4F 0x5B 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x38 0x1A 0x04 0xAF 0x01 0x11 0x00 0xFF 0x53 0x5B 0x38 0x19 0x03 0x05 0x8B 0x00 0x15 0x7A 0x04 0x22 0x19 0x8B 0x00 0x0A 0x2D 0x19 0x8B 0x00 0x11 0x5B 0x32 0xAD 0x7F;
    0x80 0xB4 0x07 0x00 0x10 0x00 0x1A 0x08 0x1F 0x8B 0x00 0x16 0x61 0x08 0x11 0x63 0x00 0x8D 0x00 0x0B 0x7A 0x7F;
    0x80 0xBC 0x07 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/StaticField.cap
    0x80 0xB2 0x08 0x00 0x00 0x7F;
    0x80 0xB4 0x08 0x00 0x0D 0x08 0x00 0x0A 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x7F;
    0x80 0xBC 0x08 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/ConstantPool.cap
    0x80 0xB2 0x05 0x00 0x00 0x7F;
    0x80 0xB4 0x05 0x00 0x20 0x05 0x00 0x5E 0x00 0x17 0x02 0x00 0x00 0x00 0x02 0x00 0x00 0x01 0x06 0x80 0x09 0x00 0x06 0x80 0x03 0x00 0x03 0x80 0x09 0x08 0x03 0x80 0x03 0x01 0x01 0x00 0x00 0x7F;
    0x80 0xB4 0x05 0x00 0x20 0x00 0x06 0x00 0x00 0x01 0x03 0x80 0x09 0x02 0x03 0x80 0x09 0x05 0x03 0x80 0x0A 0x01 0x06 0x80 0x07 0x01 0x06 0x00 0x01 0x7A 0x06 0x00 0x01 0x21 0x06 0x00 0x00 0x7F;
    0x80 0xB4 0x05 0x00 0x20 0xC5 0x06 0x00 0x01 0xAF 0x03 0x80 0x09 0x04 0x03 0x80 0x0A 0x06 0x01 0x80 0x09 0x00 0x03 0x80 0x0A 0x07 0x03 0x80 0x0A 0x09 0x03 0x80 0x0A 0x04 0x03 0x80 0x09 0x7F;
    0x80 0xB4 0x05 0x00 0x01 0x01 0x7F;
    0x80 0xBC 0x05 0x00 0x00 0x7F;
    // com/sun/javacard/samples/wallet/javacard/RefLocation.cap
    0x80 0xB2 0x09 0x00 0x00 0x7F;
    0x80 0xB4 0x09 0x00 0x20 0x09 0x00 0x3A 0x00 0x0F 0x13 0x1F 0x20 0x0D 0x69 0x41 0x11 0x05 0x05 0x41 0x0E 0x05 0x20 0x09 0x1C 0x00 0x27 0x05 0x04 0x07 0x2A 0x04 0x06 0x07 0x09 0x0D 0x07 0x7F;
    0x80 0xB4 0x09 0x00 0x1D 0x24 0x1D 0x06 0x06 0x06 0x07 0x08 0x08 0x04 0x09 0x12 0x15 0x10 0x10 0x08 0x04 0x09 0x12 0x15 0x0D 0x0F 0x05 0x0B 0x05 0x19 0x07 0x05 0x0A 0x08 0x7F;
    0x80 0xBC 0x09 0x00 0x00 0x7F;
    0x80 0xBA 0x00 0x00 0x00 0x7F;
    powerdown;this is generated by scriptgen

  • Javacard.framework.APDU sendBytes method

    In the class javacard.framework.APDU, I found that in several methods such as sendBytes(short bOff, short leng) or public void sendBytesLong(byte[] outData, short bOff, short len), they say:
    "Requiring that the buffer not be altered allows the implementation to reduce protocol overhead by transmitting the last part of the response along with the status bytes."
    I can not understand it so well. Why is it related to protocol overhead reduction? And what is "status bytes"?
    Your reply, whether helpful or not, is highly appreciated
    Jason

    So you mean when it transmits the last packet including status bytes ~~> there would be one transmission only ~~> instead of two transmissions that last data is sent first and status bytes are sent then.
    ~~> thus, one (instead of two) can reduce the slight protocol overhead
    When this process is repeated for each APDU response, it can lead to a multiple of slight overheads ~~> reduce the protocol overhead significantly
    Is that right?
    Jason

  • Is it possible send APDU´s from one applet javacard to another?

    Hi, i would like to send particular APDU from one applet javacard to another and if its possible how could i make it.
    Thanks

    Yes, it is possible.
    - Receive command APDU with applet1
    - Applet2 implements a shareable interface object (SIO)
    - Applet1 contacts applet2 through SIO
    - Applet2 process the apdu and optionally passes a response message
    Check out JCRE spec 2.2.1/2, Shareable Interfaces

  • Sent step by step apdu command to load cap file into javacard

    Dear All,
    I have log file about process loading cap file into card:
    Loading "E:\Sample.cap" ...
    T - 80F28000024F00
    C - 08A000000003000000019E9000
    ISD AID : A000000003000000
    T - 80E602001407A000000132000108A00000000300000000000000
    C - 009000
    T - 80E80000C8C48209B6010011DECAFFED010202010107A000000132000102001F0011001F00000015009A005D0772000A00C8001B03E400020000000002000004001502000107A0000000620001000107A000000062010106005D80810000C20000810200800000FF000100000000810500FF0003000000028000130008010D000002CA02DE02E202E702EE02F602FB0308032B036204AA04C804E8000009040308020705060C0D00010D040308020705060C0D090A0B010707720003201D046D06048D00141C7500120001000300
    C - 009000
    T - 80E80001C800098F00163D1D8C001A77068D001401770110188C001B7A0220181D8C001C7A03101C026B07017F001D7A7B001D670D8F001F3D1C8C00207F001D7B001D1C8B00127B001D93038903290803290903290A03290B03290D03290E707F1506160E251100FF53290C160C606D1B1604160E41251100FF53290D160D605C191E160E41251100FF531505160E251100FF53435B290F160F6308160F0245290F160F10096D075909017005590801160F10146D27160D160C432910161063081610024529101610100C6D0700
    C - 009000
    T - 80E80002C8590B01700B161010106F05590A01590E01160E1607A4FF7F1100961609411608430547290F160F630703290F700E160F1100FF6F071100FF290FAD0005160F5B38104B160B41160A43290F160F630703290F700E160F1100FF6F071100FF290FAD0007160F5B387A045603290503290603290704290803290916066008160610096F0F1B1607590701251100FF53290616056008160510096F0E191E590201251100FF532905160610096F2E160510096F281605160643290A160A6308160A0245290A160A10086D00
    C - 009000
    T - 80E80003C80C16091008160A434129095908017042160610096F0E590801160565355905FF7030160510096F0E590801160665235906FF701E160616056F0E16061605432906032905700C1605160643290503290616071604A4FF5D1609106445290916096307117FFF29091609160847290916091100FF6F071100FF2909AD000316095B387A0430191E0441251100FF5375002D00020081000D0082001B18068901191E0541251100FF537818078901191E054125191E0641258D001778191E0441251100FF53107F6E101800
    C - 009000
    T - 80E80004C8058901191E0441251100FF537803780320188C001B18110100900B870218110118900B870318110118900B870418110080900B87051808900C8706181D880718AE0788081804048D00138709181006048D00158700181006048D0015870A7A02201D046D06048D0014181D880718AE0788087A011006780110AE0B780210AD090325780310AD090303387A0110AE08780330191E1103008D00183B057805501D1604411100806F040378AE0B6106078D0014AD051D1A1F16048D00193B1604780540AD090303381800
    C - 009000
    T - 80E80005C803880B1803890C1803890D1803890E1803880F1F60081FAD05926F06058D0014191EAD05031F8D00193B1804880F7A0543032905AE0B046B06088D001419031E41257501300002FFC600110000000D058D00141819031E418C001E290618AF011E41890119AF0125066A06058D00141806881008AF01412904A800E2181916048C001E2905191604257300C800010004000F0031008600A71605AD02926F06058D0014191604AF0141AD020316058D00193B181605890CA8009AAD0603191604AF0141251100FF5300
    C - 009000
    T - 80E80006C839AD0604191604AF01410441251100FF5339AD0605191604AF01410541251100FF5339AD0606191604AF01410641251100FF5339AD0607191604AF01410741251100FF533970441605AD03926F06058D0014191604AF0141AD030316058D00193B181605890D70231605AD04926F06058D0014191604AF0141AD040316058D00193B181605890E700216041605AF014141290416041606A7FF1DAF0CAF0D41AF0E41610C058D00147006058D00147A0210AE0B046A0BAE0F6007AE10066A06088D00141804880B1800
    C - 009000
    T - 80E80007C8AE0788087A0440AD09030338AE0B6106078D0014180488111F650A18191E1F8B00217802780846032905032906032907032908AE116106088D0014AE0861040378AE107501DF00010003000918191E8C001E29091FAF011609416C6B04AF01412904705D181916041E418C001E29051916041E41257300400000000400110013004000220031702F1605652B1E160441AF0141290870201605651C1E160441AF0141290670111605650D1E160441AF01412907700216041605AF0141412904160416096FA1AD060700
    C - 009000
    T - 80E80008C8261100FF53290916091609452909AD0A0316098D00183B16069800B916079800B418191606191607AD03AD04AF0E8C0022AD0007251100FF53AD0606264510084F29091609AD0607266C14AD0903043818AE078808180388111140007816091609452909AD000716098D00183BAD0005251100FF53AD0605264510084F29091609AD0607266C14AD0903043818AE078808180388111140007816091609452909AD000516098D00183BAD0005AD0007AD0A058D0023AD0A05AD0A038D00246214AD0903043818AE0700
    C - 009000
    T - 80E80009C8880818038811114000781608604918191608AD02AF0C8C0025AD0003251100FF53AD0604264510084F29091609AD0607266C14AD0903043818AE078808180388111140007816091609452909AD000316098D00183BAD0003AD0A05AD0A078D0023AD0A07AD0A038D00246214AD0903043818AE0788081803881111400078AD09030338AE086511183D840804435B88087006058D0014037803430329047031181D160441251100FF5329051A1F160441251100FF532906160516066F040478160516066D0402781600
    C - 009000
    T - 80E8000AC80404415B29041604056CCE03780462032906042907703D181D160741251100FF531A1F160741251100FF534116064129061504160516074116065B3816061100FF6F070429067005032906160704435B2907160763C37A08000A000200010000000000000A001B0500000000000100000004000000130002002B003300090001000105009A002602001D0602001D0B02001D0002001D0102001D0202001D0302001D0402001D0D02001D0E02001D0502001D0702001D0F02001D0802001D0902001D0A02001D110200
    C - 009000
    T - 80E8000BC8001D0C02001D10038105020681080C060000330681080D01001D000681100506811006068110020600027A06800000068105000500000006000225010013000600002B03001D0D0600005906000728060006EB060001430900C8008BFF1726E2220E1F1A080808060403020809090F0302090507081D08100704040404060B0A082A04030C03260C030C050609060B060B060B060F0C030C060C030C080D02031205040B030205050A1D08061408330F0F0B0C111A020205080C060602040D09080C060602040D0900
    C - 009000
    T - 80E8800C5A03030603080602040E0205080C060602040D090303060308060204060506050039090D050508080B04050503030403FFFF06243509090D31180A2C091416081414200E690E130E270615190E19171B711B3B3C0D09233B0D092C00
    C - 009000
    Completed !
    However, I want to run step by step a command to load this cap file into card.
    When I sent "80F28000024F00", it is ok. It response: 08A000000003000000019E9000
    After that, I sent next command: 80E602001407A000000132000108A00000000300000000000000, it response as 6985.
    I don't understand why. Please help me this problem. I must do how to load this cap
    Thanks & Best Regards
    Kelvin Nguyen

    Hi,
    You need to delete the old CAP file before loading it again. The problem is that when you call INSTALL FOR LOAD it sees there is already a CAP file with that AID present.
    You can try sending a GET STATUS command listing load files to see what is on the card already. You need to delete what is present to be able to load/install again.
    Shane

  • JavaCard Memory

    I made a simple applet to test the speed of adding arrays, depending whether they are saved in EEPROM or RAM. Since working with variables stored in RAM should be faster, I was really surprised when I noticed no difference between them. I would really like to know where I went wrong, but simply can-t figure it out, so any help would be really appreciated. I used Eclipse 3.2 with JCOP Tools 3.1.1b and JCOP31 v2.2 JavaCard. The code I produced is:
    package test;
    import javacard.framework.APDU;
    import javacard.framework.ISO7816;
    import javacard.framework.Applet;
    import javacard.framework.ISOException;
    import javacard.framework.JCSystem;
    public class SimpleMemoryTest extends Applet {
         private static final short ARRAY_SIZE = 32;
         byte[] eeprom_a,  eeprom_b, eeprom_c;
         byte[] ram_a, ram_b, ram_c;
         short[] mem;
         private SimpleMemoryTest() {
              this.mem = new short[2];
         public static void install(byte[] bArray, short bOffset, byte bLength) {
              new SimpleMemoryTest().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
         public void process(APDU apdu) {
              if (selectingApplet()) return;
              byte[] buf = apdu.getBuffer();
              switch (buf[ISO7816.OFFSET_INS]) {
              case (byte) 0x00: { // Print memory info to verify where arrays are stored
                   mem[0] = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_PERSISTENT);
                   mem[1] = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT);
                   buf[0] = (byte)(mem[0] / 256);
                   buf[1] = (byte)(mem[0] % 256);
                   buf[2] = (byte)(mem[1] / 256);
                   buf[3] = (byte)(mem[1] % 256);
                   apdu.setOutgoingAndSend((short)0, (short)4);
                   break;
              case (byte) 0x01: { // Put arrays in EEPROM.
                   this.eeprom_a = new byte[ARRAY_SIZE];
                   this.eeprom_b = new byte[ARRAY_SIZE];
                   this.eeprom_c = new byte[ARRAY_SIZE];
                   break;
              case (byte) 0x02: { // Put arrays in RAM.
                   this.ram_a = JCSystem.makeTransientByteArray(ARRAY_SIZE, JCSystem.CLEAR_ON_DESELECT);
                   this.ram_b = JCSystem.makeTransientByteArray(ARRAY_SIZE, JCSystem.CLEAR_ON_DESELECT);
                   this.ram_c = JCSystem.makeTransientByteArray(ARRAY_SIZE, JCSystem.CLEAR_ON_DESELECT);
                   break;
              case (byte) 0x03: { // Add arrays in EEPROM 100 times
                   short i, j;
                   for (i = (short) 0; i < (short) 100; i++) {
                        for (j = (short) 0; j < (short) ARRAY_SIZE; j++) {
                             eeprom_c[j] = (byte)(eeprom_a[j] + eeprom_b[j]);
                   break;
              case (byte) 0x04: { // Add arrays in RAM 100 times
                   short i, j;
                   for (i = (short) 0; i < (short) 100; i++) {
                        for (j = (short) 0; j < (short) ARRAY_SIZE; j++) {
                             ram_c[j] = (byte)(ram_a[j] + ram_b[j]);
                   break;
              default:
                   ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }

    When you create a byte array, all values are initialized to 0. Looking at your loops, it seems you're adding 0's only. Smart card operating systems normally do a read before write, to make sure not the same value is written. It saves time, and in case of EEPROM also to prolong the lifetime. I think this is the reason why you see no difference .. because there is no writing. Do something like
    eeprom_c[j] = (byte)(i + j);
    Matjaz wrote:          case (byte) 0x03: { // Add arrays in EEPROM 100 times
                   short i, j;
                   for (i = (short) 0; i < (short) 100; i++) {
                        for (j = (short) 0; j < (short) ARRAY_SIZE; j++) {
                             eeprom_c[j] = (byte)(eeprom_a[j] + eeprom_b[j]);
                   break;
              case (byte) 0x04: { // Add arrays in RAM 100 times
                   short i, j;
                   for (i = (short) 0; i < (short) 100; i++) {
                        for (j = (short) 0; j < (short) ARRAY_SIZE; j++) {
                             ram_c[j] = (byte)(ram_a[j] + ram_b[j]);
                   break;

  • How can I read Extended APDU input to the same buffer

    The following is the code I am currently using where inBuffer is an intermediate array of 1000 length. However, I do not want to allocate any buffers at all, and just want to send a command apdu of 1000 byte length and modify it in the code and return the modified buf in the response APDU.
    // Read extended APDU input
    byte[] buf = apdu.getBuffer();
    short bytesRead = apdu.setIncomingAndReceive();
    short dataOffset = apdu.getOffsetCdata();
    // store first chunk in our intermediate byte array <-- how do i get rid of the intermediate array
    Util.arrayCopyNonAtomic(buf, dataOffset, inBuffer, (short) 0, bytesRead);
    // what is the overall length?
    short overallLength = apdu.getIncomingLength();
    short messageOffset = bytesRead;
    if (bytesRead != overallLength){ // otherwise we're finished, all bytes received
         short received = 0;
         do{
                   received = apdu.receiveBytes((short)0);
                   Util.arrayCopyNonAtomic(buf, (short)0, inBuffer, messageOffset, received);
                   messageOffset  += received;
              } while(received != 0);
    * REST OF CODE IN PROCESS METHOD
    I have also tried replacing the above code with the following
    short bytesLeft = (short) (buffer[ISO7816.OFFSET_LC] & 0x00FF);
    if (bytesLeft < (short)55) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH );
    short readCount = apdu.setIncomingAndReceive();
    while ( bytesLeft > 0){
      // process bytes in buffer[5] to buffer[readCount+4];
      bytesLeft -= readCount;
      readCount = apdu.receiveBytes ( ISO7816.OFFSET_CDATA );
    as shown in the javadocs API, but it does not compile.
    This is my command APDU:
    /send 800100000003E8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003E8
    As you can see:
    CLA - 80
    INS - 01
    P1 & P2 - 00
    LC - 0003E8
    Data - 1000 0s
    LE - 03E8
    I am using JavaCard 3.0 with JCOP in Eclipse. How can I read the extended length apdu to the same buffer? I have no problem in returning an extended length response APDU. Thanks a lot for the help.

    You should not call the convenience method setIncomingAndReceive() in your first code. Please find out about the different APDU states. Furthermore, your Applet should implement the ExtendedLength tagging interface.

  • Error while sending an APDU 6d 00

    Hello,
    I'm testing Javacard and i just want to send vie smartcard io an apdu command 0x80 0x07 0x00 0x00.
    As an response i should get: a simple string back.
    However, it doesen't work. After I selected more or less every ins byt eI'm sending results in an 6d00.
    But if I'm sending it via the APDUTOOL I'm getting the correct answer??
    Must have something to do with the transformation from in to byte. But I don't see where...
    Here is the java code:
    public class SCcommunication {
         private TerminalFactory factory;
         private List<CardTerminal> terminals;
         private CardTerminal terminal;
         private Card card;
         private CardChannel channel;
         private ResponseAPDU response;
         private boolean protocollType;
         private int sendLength;
         private int selectLength; //00 A4 04 00 + LE + aid
         private byte send[], select[];
         private CommandAPDU command;
         //generate a factory, get terminal list, and take the first terminal available (get(0))!
         public SCcommunication(){
              factory= TerminalFactory.getDefault();
              try{
                   terminals = factory.terminals().list();
              catch (CardException ec){
                   ec.printStackTrace();
              terminal = terminals.get(0);
              //if protocolltype=flase then protocoll is T0 else T1
              protocollType=false;
              selectLength=13;
              sendLength=133;
              select= new byte[selectLength];
              select[0]=(byte)(0x00);select[1]=(byte)(0xA4);select[2]=(byte)(0x04);select[3]=(byte)(0x0); select[4]=(byte)(8);
              select[5]=(byte)(0xAB); select[6]=(byte)(0xCD); select[7]=(byte)(0xEF); select[8]=(byte)(0xFE); select[9]=(byte)(0xDC); select[10]=(byte)(0x12);
              select[11]=(byte)(0x34); select[12]=(byte)(0x56); //select[13]=(byte)(0x01); select[14]=(byte)(0x01);
              send= new byte[sendLength];
         public void switchProtocoll(){
              if (!protocollType==true)
                   protocollType=false;
              else
                   protocollType=true;
         public void selectApplet(byte selectAPDU[]){
              try{
              if (protocollType)
                   card = terminal.connect("T=0");
              else
                   card = terminal.connect("T=1");
              channel= card.getBasicChannel();
              response=channel.transmit(new CommandAPDU(select));
              byte respByte[]=response.getBytes();
              System.out.print("The response: ");
              System.out.println();
              for (int i=0;i<respByte.length;i++){     
                   System.out.print(Integer.toHexString(respByte&0xff)+"||");
              System.out.println();
              // the card is not reseted after disconnect, due to false
              card.disconnect(false);
              catch (CardException ec){
                   ec.printStackTrace();
         public void sendToCard(){
              try{
                   if (protocollType)
                        card=terminal.connect("T=0");
                   else
                        card=terminal.connect("T=1");
                   channel= card.getBasicChannel();
                   //response=channel.transmit(new CommandAPDU(send));
                   send[0]=(byte)0x80; send[1]=(byte)0x07; send[2]=(byte)(0x00);send[3]=(byte)(0x00); send[4]=(byte)(128);
                   System.out.println("The response: ");
                   response=channel.transmit(new CommandAPDU(send));
                   byte respByte[]=response.getBytes();
                   for (int i=0;i<respByte.length;i++){
                        System.out.print(Integer.toHexString(respByte[i]&0xff)+"||");
                   System.out.println();
                   System.out.println("Done");
              // the card is not reseted after disconnect, due to false
                        card.disconnect(false);
              catch (CardException ec){
                   ec.printStackTrace();
         public static void main (String args[]){
              SCcommunication sc = new SCcommunication();
              sc.switchProtocoll();
              sc.selectApplet(sc.select);
              sc.sendToCard();
    Here is the corresponending Java Card code:
    public void process(APDU apdu) throws ISOException {
              // this is the text string which will send back from the ICC to the IFD
              final byte[] text = {(byte) 'H', (byte) 'l', (byte) 'l', (byte) ' ',
              (byte) 'o', (byte) 'M', (byte) 'n', (byte) 'a', (byte) 'm', (byte) ' ',
              (byte) 'e', (byte) 'i', (byte) 's', (byte) 'C',
              (byte) 'h', (byte) 'a', (byte) 'r', (byte) 'l', (byte) 'y'};
              // this is the install method which will be called once for installation
              // and registration of the applet
              // this is the method, which will be called from JCRE
              // the cmd_apdu variable is used because of performance reasons
              byte[] cmd_apdu = apdu.getBuffer();
              if (cmd_apdu[0] ==(byte)0x80) {  // it is the rigth class   
              short len_text = (short)text.length; // the len_text variable is used because of performance reasons
              apdu.setOutgoing(); // set transmission to outgoing data
              apdu.setOutgoingLength((short)len_text); // set the number of bytes to send to the IFD
              apdu.sendBytesLong(text, (short)0, (short)len_text);
              } // if
                   else{
                        ISOException.throwIt(ISO7816.SW_NO_ERROR);
              } // process
    Does anybode have any idea?
    Best regards

    Repost with code tgas:
    866393 wrote:
    Hello,
    I'm testing Javacard and i just want to send vie smartcard io an apdu command 0x80 0x07 0x00 0x00.
    As an response i should get: a simple string back.
    However, it doesen't work. After I selected more or less every ins byt eI'm sending results in an 6d00.
    But if I'm sending it via the APDUTOOL I'm getting the correct answer??
    Must have something to do with the transformation from in to byte. But I don't see where...
    Here is the java code:
    public class SCcommunication {
         private TerminalFactory factory;
         private List<CardTerminal> terminals;
         private CardTerminal terminal;
         private Card card;
         private CardChannel channel;
         private ResponseAPDU response;
         private boolean protocollType;
         private int sendLength;
         private int selectLength; //00 A4 04 00 + LE + aid
         private byte send[], select[];
         private CommandAPDU command;
         //generate a factory, get terminal list, and take the first terminal available (get(0))!
         public SCcommunication(){
              factory= TerminalFactory.getDefault();
              try{
                   terminals = factory.terminals().list();
              catch (CardException ec){
                   ec.printStackTrace();
              terminal = terminals.get(0);
              //if protocolltype=flase then protocoll is T0 else T1
              protocollType=false;
              selectLength=13;
              sendLength=133;
              select= new byte[selectLength];
              select[0]=(byte)(0x00);select[1]=(byte)(0xA4);select[2]=(byte)(0x04);select[3]=(byte)(0x0); select[4]=(byte)(8);
              select[5]=(byte)(0xAB); select[6]=(byte)(0xCD); select[7]=(byte)(0xEF); select[8]=(byte)(0xFE); select[9]=(byte)(0xDC); select[10]=(byte)(0x12);
              select[11]=(byte)(0x34); select[12]=(byte)(0x56); //select[13]=(byte)(0x01); select[14]=(byte)(0x01);
              send= new byte[sendLength];
         public void switchProtocoll(){
              if (!protocollType==true)
                   protocollType=false;
              else
                   protocollType=true;
         public void selectApplet(byte selectAPDU[]){
              try{
              if (protocollType)
                   card = terminal.connect("T=0");
              else
                   card = terminal.connect("T=1");
              channel= card.getBasicChannel();
              response=channel.transmit(new CommandAPDU(select));
              byte respByte[]=response.getBytes();
              System.out.print("The response: ");
              System.out.println();
              for (int i=0;i<respByte.length;i++){     
                   System.out.print(Integer.toHexString(respByte&0xff)+"||");
              System.out.println();
              // the card is not reseted after disconnect, due to false
              card.disconnect(false);
              catch (CardException ec){
                   ec.printStackTrace();
         public void sendToCard(){
              try{
                   if (protocollType)
                        card=terminal.connect("T=0");
                   else
                        card=terminal.connect("T=1");
                   channel= card.getBasicChannel();
                   //response=channel.transmit(new CommandAPDU(send));
                   send[0]=(byte)0x80; send[1]=(byte)0x07; send[2]=(byte)(0x00);send[3]=(byte)(0x00); send[4]=(byte)(128);
                   System.out.println("The response: ");
                   response=channel.transmit(new CommandAPDU(send));
                   byte respByte[]=response.getBytes();
                   for (int i=0;i<respByte.length;i++){
                        System.out.print(Integer.toHexString(respByte[i]&0xff)+"||");
                   System.out.println();
                   System.out.println("Done");
              // the card is not reseted after disconnect, due to false
                        card.disconnect(false);
              catch (CardException ec){
                   ec.printStackTrace();
         public static void main (String args[]){
              SCcommunication sc = new SCcommunication();
              sc.switchProtocoll();
              sc.selectApplet(sc.select);
              sc.sendToCard();
    Here is the corresponending Java Card code:
    public void process(APDU apdu) throws ISOException {
              // this is the text string which will send back from the ICC to the IFD
              final byte[] text = {(byte) 'H', (byte) 'l', (byte) 'l', (byte) ' ',
              (byte) 'o', (byte) 'M', (byte) 'n', (byte) 'a', (byte) 'm', (byte) ' ',
              (byte) 'e', (byte) 'i', (byte) 's', (byte) 'C',
              (byte) 'h', (byte) 'a', (byte) 'r', (byte) 'l', (byte) 'y'};
              // this is the install method which will be called once for installation
              // and registration of the applet
              // this is the method, which will be called from JCRE
              // the cmd_apdu variable is used because of performance reasons
              byte[] cmd_apdu = apdu.getBuffer();
              if (cmd_apdu[0] ==(byte)0x80) {  // it is the rigth class   
              short len_text = (short)text.length; // the len_text variable is used because of performance reasons
              apdu.setOutgoing(); // set transmission to outgoing data
              apdu.setOutgoingLength((short)len_text); // set the number of bytes to send to the IFD
              apdu.sendBytesLong(text, (short)0, (short)len_text);
              } // if
                   else{
                        ISOException.throwIt(ISO7816.SW_NO_ERROR);
              } // process
    Does anybode have any idea?
    Best regards

  • Proprietary APDU CLA byte

    Hi,
    If I am creating proprietary APDU for the JavaCard applet. I think the CLA byte should be 0x80, because the 4 top most bits must be 1000 according to ISO/IEC 7816
    and if I will not use the secure messaging and logical channels, the lower 4 bits must be 0000, which is 10000000 = 0x80.
    Am I right?
    Regards,
    STeN

    Hello,
    thanks for the reply - sure I must avoid the possible collision with the Global Platform!
    Other question - I think - but I am not sure about this - if the smart card manufacturer supports some extra proprietary APDUs (e.g. enumerating installed JavaCard applets, getting the free EEPROM space) by the smart card OS (i.e. Sm@rtCafe), I should also check those commands, to avoid possible collision, because I think those commands will be handled with higher priority then applet specific APDUs (by this I mean, that if I will send the APDU and OS detect that this is a command it supports, it will handle it and the APDU will nto be sent to the currently selected JavaCard applet)?
    Thanks a lot for the reply and help
    Regards,
    STeN

  • RSA Keypair cannot be generated in javacard ?

    Hello
    I got a problem about how to generate a RSA keypair in JAVACARD, I tried many different parametres, but I cannot install my applet in my emulator.
    public class RSAencry extends Applet {
        RSAPrivateKey  rsa_PrivateKey;
        RSAPublicKey rsa_PublicKey;
        KeyPair rsa_KeyPair;
        Cipher cipherRSA;
        //private byte buffer[];
        //byte TheBuffer[];
        final short dataOffset = (short) ISO7816.OFFSET_CDATA;
        //constructor
        private RSAencry()
            //generate own rsa_keypair
             //rsa_KeyPair = new KeyPair( KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048 );
             //super();
             try
             //TheBuffer = new byte[100];
             rsa_KeyPair = new KeyPair( KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_512 );
             //rsa_PublicKey.setExponent (TheBuffer, (short)0, (short)1);
             rsa_KeyPair.genKeyPair();
            rsa_PublicKey = (RSAPublicKey) rsa_KeyPair.getPublic();
            //rsa_PrivateCrtKey = (RSAPrivateCrtKey) rsa_KeyPair.getPrivate();
            rsa_PrivateKey = (RSAPrivateKey) rsa_KeyPair.getPrivate();
            //buffer = new byte[2048];
            cipherRSA = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
             }catch (CryptoException ex){
                  ISOException.throwIt((short) (ex.getReason()));
            //register(bArray, (short) (bOffset), bArray[bOffset]);
         public static void install(byte[] bArray, short bOffset, byte bLength) {
              // GP-compliant JavaCard applet registration
              new RSAencry().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
         public void process(APDU apdu) {
              // Good practice: Return 9000 on SELECT
              if (selectingApplet()) {
                   return;
              byte[] buf = apdu.getBuffer();
              switch (buf[ISO7816.OFFSET_INS]) {
              case (byte) 0x00:
                   break;
              default:
                   // good practice: If you don't know the INStruction, say so:
                   ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }The log shows as below:
    (2233 usec)
    <= 00 90 00 ...
    Status: No Error
    Load report:
    1358 bytes loaded in 0.0 seconds
    effective code size on card:
    + package AID 6
    + applet AIDs 15
    + classes 17
    + methods 138
    + statics 0
    + exports 0
    overall 176 bytes
    cm> install -i 525341656e637279 -q C9#() 525341656e63 525341656e637279
    => 80 E6 0C 00 1F 06 52 53 41 65 6E 63 08 52 53 41 ......RSAenc.RSA
    65 6E 63 72 79 08 52 53 41 65 6E 63 72 79 01 00 encry.RSAencry..
    02 C9 00 00 00 .....
    (122771 usec)
    <= 6A 80 j.
    Status: Wrong data
    jcshell: Error code: 6a80 (Wrong data)
    jcshell: Wrong response APDU: 6A80
    Unexpected error; aborting execution
    I almost removed all other codes, but it still can not intalled in card emulator.
    Does anyone can tell me that's why?
    Edited by: 949003 on 2012-8-3 上午8:05
    Edited by: 949003 on 2012-8-3 上午8:07

    Thanks Shane
    I even removed those senteces.
    public class RSAencry extends Applet {
        private KeyPair rsa_KeyPair;
        Cipher cipherRSA;
        //constructor
        private RSAencry()
             try
             new KeyPair( KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048 );
             rsa_KeyPair.genKeyPair();
             }catch (CryptoException ex){
                  ISOException.throwIt((short) (ex.getReason()));
            //register(bArray, (short) (bOffset), bArray[bOffset]);
         public static void install(byte[] bArray, short bOffset, byte bLength) {
              // GP-compliant JavaCard applet registration
              new RSAencry().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
         public void process(APDU apdu) {
              // Good practice: Return 9000 on SELECT
              if (selectingApplet()) {
                   return;
              byte[] buf = apdu.getBuffer();
              switch (buf[ISO7816.OFFSET_INS]) {
              case (byte) 0x00:
                   break;
              default:
                   // good practice: If you don't know the INStruction, say so:
                   ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }and I still got this log
    Status: No Error
    Load report:
    1089 bytes loaded in 0.0 seconds
    effective code size on card:
    + package AID 6
    + applet AIDs 15
    + classes 17
    + methods 101
    + statics 0
    + exports 0
    overall 139 bytes
    cm> install -i 525341656e637279 -q C9#() 525341656e63 525341656e637279
    => 80 E6 0C 00 1F 06 52 53 41 65 6E 63 08 52 53 41 ......RSAenc.RSA
    65 6E 63 72 79 08 52 53 41 65 6E 63 72 79 01 00 encry.RSAencry..
    02 C9 00 00 00 .....
    (7334 usec)
    <= 6A 80 j.
    Status: Wrong data
    jcshell: Error code: 6a80 (Wrong data)
    jcshell: Wrong response APDU: 6A80
    Unexpected error; aborting execution

  • Problem in APDU-case 1:No command,no response

    Hello evrybody.I have done a method in my java card applet which does not return any command data neither response data.
    I wrote in my APDU script the following(as defined the case 1 in the Zhiqun Chen's book-page 102,says that "P3(the 5th field in the APDU buffer) has to be 0"):
    //CLA INS P1 P2 P3
    0xB1 0x50 0x00 0x00 0x00;
    Howevr, the executed APDU script returns me the following:
    com.sun.javacard.apdutool.ReaderWriterError: Encountered ";" at line 105, column
    25.
    Was expecting one of: <INTEGER_LITERAL> ...
    <CHARACTER_LITERAL> ...
    <STRING_LITERAL> ...
    I have tried to add another 0x00 byte at the end of the above script line, as follwoing:
    //CLA INS P1 P2 Lc Le
    0xB1 0x50 0x00 0x00 0x00 0x00;
    //WIth the idea that Lc=0(no command data) and Le=0(no response data)
    I noticed that the method is working properly(does the work that has to do;I tested and I am definetely sure) but on the other hand the executed APDU script returns as SW1 SW2 the following:
    CLA: b1, INS: 50, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 6f, SW2: 00 (!!!!)
    Actually,I was waiting for SW1 SW2 == 90 00.
    I do not know why this is returned.
    Do you know what it is going wrong?
    I will appreciate any help and guidance.
    Thank you for you time.

    I will give the code of my function.I think the problem is in the code of this method(function).I will give you in order to have a look at it:
    private void delete_all_records(APDU apdu)
         ver_pin();
         byte[] buffer=apdu.getBuffer();
         byte get_P1=buffer[ISO7816.OFFSET_P1];
         byte P3=buffer[ISO7816.OFFSET_LC];
         //Check the appropriate syntax
         if (get_P1!=(byte)0) // || (P3!=(byte)0) )
         ISOException.throwIt (SW_SYNTAX_DEL_ERROR);
    // else
         //Delete all the record.This for loop
         //deletes all the records' ids.
         for (short i=0;i<kostas.length;i++)
         kostas[(short)i].record_id=(byte)0;
    I did not use any of the functions such as sendBytes() or apdu.setIncomingAndReceive because I did not want to take data either to return response data.Do you have any idea what's going on?
    I will really apprecitae any help.Thank you for your time.

  • Problem with select APDU

    Hi all
    I have a problem when trying to test an applet created by me like Sebastian Lorquet proposed in this post:
    Re: Ask Global Platform SecureChannel
    I managed to install my applet on the card, and when I check the applets it contains I can see that the AID of mine appears.
    But when I use it and send APDUs through it, the SELECT command fails me.
    The SELECT APDU instruction is:
    Command -> 00A404000B0102030405060708090000
    where 01 02 03 04 05 06 07 08 09 00 00 is the AID of my applet
    The response is as follows:
    Response <- 6D00 (Invalid instruction byte / Command not supported or invalid)
    Do not understand why I get that answer.
    I am using gpshell, and the command used is:
    select -AID 0102030405060708090000
    Thanks in advance
    Edited by: bra_racing on 05-jul-2012 15:28

    ah ok. Just answer me one thing, are you using below code ?
    package test;
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import org.globalplatform.GPSystem;
    import org.globalplatform.SecureChannel;
    * @author shane
    public class TestSecureChannel extends Applet {
        private final static byte INS_INIT_UPDATE = 0x50;
        private final static byte INS_EXT_AUTH = (byte) 0x82;
        private TestSecureChannel() {
            // empty
        public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
            new TestSecureChannel().register();
        public void process(APDU apdu) throws ISOException {
            if (selectingApplet()) {
                return;
            byte[] buffer = apdu.getBuffer();
            byte cla = buffer[ISO7816.OFFSET_CLA];
            byte ins = buffer[ISO7816.OFFSET_INS];
            SecureChannel sc = GPSystem.getSecureChannel();
            if ((byte) (cla & 0x80) == 0x80) {
                switch (ins) {
                    case INS_INIT_UPDATE:
                    case INS_EXT_AUTH:
                        apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, sc.processSecurity(apdu));
                        return;
                    default:
                        // fall through
            switch (ins) {
                case (byte) 0x01:
                    buffer[0] = sc.getSecurityLevel();
                    apdu.setOutgoingAndSend((short) 0, (short) 1);
                    break;
                default:
                    ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }If not above one then copy past your code here. For time being for what I understand it that to send get data command your currently selected application should be card manager.
    Edited by: Umer on Jul 10, 2012 4:34 PM

  • Error "Cannot be resolved to a type" on OwnerPIN, APDU, ISO7816

    The error I'm reffering to might clearify the fact that I'm new at Java/javaCard-development.
    To learn how it all works I've downloaded an example and try to understand what happens.
    I opened the source in Eclipse and get errors "Cannot be resolved to a type" on OwnerPIN, ADPU and ISO7816 classes. I have an Import javacard.framework statement and expected these types to be part of this library.
    I guess I'm forgetting something somewhere but couldn't find the soluiton on internet.
    import javacard.framework.*; // import all neccessary packages for java card*
    import java.applet.;
    import java.lang.Object;
    public class classpgdata extends Applet {
    final static byte PROP_CLASS = (byte) 0x80; // Class of the proprietary APDU commands
    static {color:#ff0000}OwnerPIN{color} pin; // the PIN object
    public void process({color:#ff0000}APDU{color} apdu) {
    byte[] cmd_apdu = apdu.getBuffer();
    if (cmd_apdu[{color:#ff0000}ISO7816{color}.OFFSET_CLA] == {color:#ff0000}ISO7816{color}.CLA_ISO7816) {
    //----- it is the ISO/IEC 7816 class
    switch(cmd_apdu[{color:#ff0000}ISO7816{color}.OFFSET_INS]) { // check the instruction byte
    case INS_SELECT: // it is a SELECT FILE instruction
    ...

    Hi,
    What you need to do update your Java build path fr the project in your Eclipse project.
    Project -> Properties then find Java Build Path.
    In the Libraries tab add the {JCDK Home}/lib/javacardframework.jar by clicking the add external JARs button. You may also want to remove the standard Java Runtime (JRE) libraries as you do not build against these.
    If you want to use the JC 2.2.1 CAP file converter, you may also want to ensure that the Eclipse compiler is set to compile as Java 1.3 in the Java Compiler section of the project properties.
    KeesdeVink wrote:
    import javacard.framework.*; // import all neccessary packages for java card
    import java.applet.*;
    import java.lang.Object;
    It also looks like you have added two imports you don't actually want. You only need the javacard.framework.* import.
    Cheers,
    Shane
    Edited by: safarmer on 23/09/2009 08:00

  • How to create file with APDU

    Hello everybody,
    It's my first time using Java Card ^_^,I want to create a file and fill the fill with binary data.but i don't know how to create file with APDU commands,so I need help here.
    I think that there must be a Manual of the JavaCard's OS in this world,can someone tell me where to download it??
    Thanks.
    the fllowing is my card:
    Samsung S1
    Model:TiEx-32J
    EEPROM size:32k
    Platform Version:OP 2.0.1
    Card Manager Status:OP_READY
    KMC:40~4F/No derivation
    Message was edited by:
    AllenHuang

    If you look around the forum for a bit, you will see that there is no notion of file systems on JavaCards (lexdabear posted this information less than two hours ago :-)). To store files, you will have to write an applet to hold byte arrays of the required size and handle receiving and sending of these.
    As for documentation, you should have a look at the GP (General Platform) specification at http://www.globalplatform.org/, which defines communication between smart cards and other devices, as well as Sun's own JavaCard pages (http://java.sun.com/products/javacard/), which contain several useful resources on JavaCards.
    Message was edited by:
    Lillesand

  • Create file on javacard

    Hi
    I want to store a picture on my javacard.
    Is there a way to do it ?
    I think it will be easy if i put the byte[] on a file but i don t know if it s possible to creat a file in a javacard ?
    could i have some help please ?
    thanks

    Hi,
    Storing an image in javacard is as simple as storing it in a byte array. The difficulty comes with any other requirements you have. With an image you will most likely need to add some kind of apdu command and response chaining.
    An overly simplified version of the applet is:
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.Util;
    import javacardx.apdu.ExtendedLength;
    * Basic applet for reading and writing an image file using extended length APDU's.
    * @author shane
    public class BasicApplet extends Applet implements ExtendedLength {
      private final static byte INS_WRITE_FILE = 0x00;
      private final static byte INS_READ_FILE = 0x01;
      private final static short MAX_IMAGE_SIZE = (short) ((10 * 1024) + 2);
      private byte[] imageFile = new byte[MAX_IMAGE_SIZE];
      private final static byte OFF_LEN = 0x00;
      private final static byte OFF_IMAGE = 0x02;
      public static void install(byte[] bArray, short bOffset, byte bLength) {
        // GP-compliant JavaCard applet registration
        new BasicApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
      public void process(APDU apdu) {
        // Good practice: Return 9000 on SELECT
        if (selectingApplet()) {
          return;
        byte[] buf = apdu.getBuffer();
        switch (buf[ISO7816.OFFSET_INS]) {
          case INS_WRITE_FILE:
            short inlen = apdu.setIncomingAndReceive();
            Util.setShort(imageFile, OFF_LEN, inlen);
            Util.arrayCopyNonAtomic(buf, apdu.getOffsetCdata(), imageFile, OFF_IMAGE, inlen);
            break;
          case INS_READ_FILE:
            short outlen = Util.getShort(imageFile, OFF_LEN);
            apdu.setOutgoing();
            apdu.setOutgoingLength(outlen);
            apdu.sendBytesLong(imageFile, OFF_IMAGE, outlen);
            break;
          default:
            // good practice: If you don't know the INStruction, say so:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    }I am certain this wont meet your requirements yet, but it is a start to learning what you need to solve the problem.
    Disclaimer: the code above has not been tested other than the fact it compiles :)
    - Shane

Maybe you are looking for

  • Can I Auto format the first paragraph on every page of a 20 page document?

    So I have a document that is basically just a numbered list of 200 entries. There are 10 entries per page, making it a 20 page document. Unfortunately, every so often I am given an additional entry to add, which invariaby is to the middle of the docu

  • Looking to buy a new audio head for my truck.

    I have a Pioneer audio unit in my Truck and it runs Windows CE.  It takes ages to boot, (typically I am a 1/4 mile down the road before it completes), crashes and prematurely ends music files while playing them.  I am looking for an upgrade.  I don't

  • Need Screen exit

    Hi Frnds, my requirement is to add custom fields to VA01 transaction 'Additional data B' tab. so please let  me know if any screen exits available for this and if possible detailed steps also. thanks n regards, KP

  • When will Apple stores have I phone 6 back in stock?

    I'm trying to purchase an I Phone 6 but they are out of stock in all UK stores.   Does anyone know when they will be back in stock?

  • Select from local (tmp) Table in Function - Table not found

    Hi, I want to create a cursor which selects from a Table which does not exist in database. I create this table as local table (how is it called? nested table?). Not shown in the code but I want to fill this local table later. After filled my cursor i