Randomdata in javacard

hi all,
Does anybody know how to use the javacard.security .Randomdata class ?
and can you tell me how to implement the generateData and setseed methods of the abstract RandomData class or give me sample program....
thanks.

hi,
if you read the documentation provided by sun, it tell that the random is a abstract class, but this documentation explained what it needed to implement a JCVM into javacard.
And all card provider implemented this norm into card and some difference between provider can be discover.
It's my analysis and i'm not really sure that it's all right.
For exemple Gemplus implemented a Random class that is not abstract and you can used it.
you must simply import the javacard.security.randomData;
created object and get the instance of it.
RandomData rnd = RandomData.getInstance(rnd."Algo");
And after used it ...

Similar Messages

  • Why I got Error with RandomData

    Dear,
    In my code, I tried to use the RandomData class.
    I use Java_card_kit-2_2. the code is as fellow:
    RandomData random_data = RandomData.getInstance(javacard.security.RandomData.ALG_SECURE_RANDOM);
    random_data.generateData((byte[])buffer, (short)0, (short)31);
    In my display, i receive SW1: 6f, SW2: 00
    please help.

    Dear,
    I haven't any dollar euxx :(
    Yes Eddy, the buffer is allocated. If you want, the code is
    byte[] buffer = apdu.getBuffer();
    short le = apdu.setOutgoing();
    RandomData random_data = RandomData.getInstance(javacard.security.RandomData.ALG_SECURE_RANDOM);
    random_data.setSeed(randomChallenge, (short)0, (short)31);
    random_data.generateData(randomChallenge, (short)0, (short)31);
    apdu.sendBytesLong(randomChallenge, (short)0, (short)31);
    It return SW1:6F, SW2:00
    i.e. the Sun's reference implemantation (version 2.2), the setSeed is as abstract, Must i define it?
    Thank you

  • Problems using javacard.security.*

    I'm tyring to use the javacard.security package classes but I have the following problem with all the classes I've tryied (namely Signature, RandomData, KeyBuilder and KeyPair):
    All this classes builder methods require a byte indicating the kind of algorithm to be used. There are static final variables in each classes which represent each of this algorithms. My problem is that, when I use any of them, I always get stuck with a NO_SUCH_ALGORITHM exception.
    Oddly enough when I use a byte different from these I don't get that exception and it seems to work but if I try to use any other method of the class I get an 6f 00 error.
    Any ideas of the problem?
    (If it matters, I'm usen the cref utility to emulate the card)
    Thanks in advance
    Jorge

    The javacard.security interfaces shipped with the kit are EMPTY ! They are coded to return NO_SUCH_ALGORITHM regardless of what you pass them.
    Download the source code. I can't remember but I think it's available from the JC2.1 kit.

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

  • Javacard and session variables

    Hello,
    I'm trying to find a reasonable Javacard technique to handle "session variables" that must be kept between successive APDUs, but must be re-initialized on each card reset (and/or each time the application is selected); e.g. currently selected file, currently selected record, current session key, has the user PIN been verified...
    Such variables are best held in RAM, since changing permanent (EEPROM or Flash) variables is so slow (and in the long run limiting the operational life of the card).
    Examples in the Java Card Kit 2.2.2 (e.g. JavaPurseCrypto.java) manipulate session variables in the following way:
    1) The programmers group session variables of basic type (Short, Byte, Boolean) according to type, and map each such variable at an explicit index of a vector (one per basic type used as session variable).
    2) At install() time, each such vector, and each vector session variable, is explicitly allocated as a transient object, and this object is stored in a field of the application (in permanent memory), where it remains across resets.
    3) Each use of a session variable of basic type is explicitly translated by the programmer into using the appropriately numbered element of the appropriate vector.
    4) Vector session variables require no further syntactic juggling, but eat up an object descriptor worth of permanent data memory (EEPROM or Flash), and a function call + object affectation worth of applet-storage memory (EEPROM, Flash or ROM).
    The preparatory phase goes:
    public class MyApp extends Applet  {
    // transientShorts array indices
        final static byte       TN_IX = 0;
        final static byte       NEW_BALANCE_IX=(byte)TN_IX+1;
        final static byte      CURRENT_BALANCE_IX=(byte)NEW_BALANCE_IX+1;
        final static byte      AMOUNT_IX=(byte)CURRENT_BALANCE_IX+1;
        final static byte   TRANSACTION_TYPE_IX=(byte)AMOUNT_IX+1;
        final static byte     SELECTED_FILE_IX=(byte)TRANSACTION_TYPE_IX+1;
        final static byte   NUM_TRANSIENT_SHORTS=(byte)SELECTED_FILE_IX+1;
    // transientBools array indices
        final static byte       TRANSACTION_INITIALIZED=0;
        final static byte       UPDATE_INITIALIZED=(byte)TRANSACTION_INITIALIZED+1;
        final static byte   NUM_TRANSIENT_BOOLS=(byte)UPDATE_INITIALIZED+1;
    // remanent variables holding reference for transient variables
        private short[]     transientShorts;
        private boolean[]   transientBools;
        private byte[]      CAD_ID_array;
        private byte[]      byteArray8;  // Signature work array
    // install method
        public static void install( byte[] bArray, short bOffset, byte bLength ) {
             //Create transient objects.
            transientShorts = JCSystem.makeTransientShortArray( NUM_TRANSIENT_SHORTS,
                JCSystem.CLEAR_ON_DESELECT);
            transientBools = JCSystem.makeTransientBooleanArray( NUM_TRANSIENT_BOOLS,
                JCSystem.CLEAR_ON_DESELECT);
            CAD_ID_array = JCSystem.makeTransientByteArray( (short)4,
                JCSystem.CLEAR_ON_DESELECT);
            byteArray8 = JCSystem.makeTransientByteArray( (short)8,
                JCSystem.CLEAR_ON_DESELECT);
    (..)and when it's time for usage, things go:
        if (transientShorts[SELECTED_FILE_IX] == (short)0)
            transientShorts[SELECTED_FILE_IX] == fid;
        transientBools[UPDATE_INITIALIZED] =
            sig.verify(MAC_buffer, (short)0, (short)10,
                byteArray8, START, SIGNATURE_LENGTH);I find this
    a) Verbose and complex.
    b) Error-prone: there is nothing to prevent the accidental use of transientShorts[UPDATE_INITIALIZED].
    c) Wastefull of memory: each use of a basic-type state variable wastes some code; each vector state variable wastes an object-descriptor worth of permanent data memory, and code for its allocation.
    d) Slow at runtime: each use of a "session variable", especially of a basic type, goes thru method invocation(s) which end up painfully slow (at least on some cards), to the point that for repeated uses, one often attain a nice speedup by caching a session variable, and/or transientShorts and the like, into local variables.
    As an aside, I don't get if the true allocation of RAM occurs at install time (implying non-selected applications eat up RAM), or at application selection (implying hidden extra overhead).
    I dream of an equivalent for the C idiom "struct of state variables". Are these issues discussed, in a Sun manual, or elsewhere? Is there a better way?
    Other desperate questions: does a C compiler that output Javacard bytecode make sense/exists? Or a usable Javacard bytecode assembler?
    Francois Grieu

    Interesting post.
    I don't have a solution to your problem, but caching the session variables arrays in local variable arrays is a good start. This should be only done when the applet is in context, e.g. selected or accessed through the shareable interface. This values should be written back to EEPROM at e.g. deselect or some other important point of time. Do you run into problems if a tear happens? I don't think so since the session variables should be transactional, and a defined point will commit a transaction.
    Analyzing the bytecode is a good idea. I know of a view in JCOP Tools (Eclipse plugin) where you can analyze the bytecode and optimize it to your needs.

  • 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

  • Is there a way to check if the smart card is a JavaCard

    Hi,
    This may sound very basic, but I am not sure how would i tell if the card is a JavaCard or not, provided i do not have any keys
    Do you guys have any solution :)
    Thanks
    AQ

    So i understand the ATR is not that helpful, but anyways this is the ATR
    ATR : 3B 9F 95 80 1F C3 80 31 E0 73 FE 21 1B 64 06 90 62 00 82 90 00 32
    There are no ascii characters so i understand nothing useful here, but only anyone can identify the card based on experience.
    The Select method sounds reasonable, and i tried it and it returns me 6A87 (Lc inconsistent with P1 P2)
    So its not GP compliant atleast
    One more thing I need to ask. what is ISD ? An applet or an ADF ?
    Thanks again guys
    You rock

  • Structure Or Record In JavaCard Framework

    Can anybody please tell me if there is a way to define or implement records or structures in Javacard Framework??
    My IDE is eclipse and I have so many master_detail data to store in Javacard, because my card does not support DB storage(SCQL) I'm searching a way better than storring data just in arrays...
    any idea about better kind of storring data on card would be so much appreciated --<--@
    my data are some thing like this:
    Name,Family,Age,Sex,CreditNo,....
    and also:
    Master : DateOfVisit, TimeOfVisit, CodeOfVisit
    Detail: IndexCode, DrugName, DrugInstruction
    an Example is ::
    Name:Hana
    Family:Bijani
    Age:25
    Sex:Femail
    CreditNo:176.3434
    Data1
    DateOfVisit:2009-08-08
    TimeOfVisit:14:23
    CodeOfVisit:123
    IndexCode:1 DrugName:Drug A DrugInstruction: someinstructA
    IndexCode:2 DrugName:Drug B DrugInstruction: someinstructB
    Data2
    DateOfVisit:2009-08-06
    TimeOfVisit:14:23
    CodeOfVisit:12345
    IndexCode:1 DrugName:Drug A DrugInstruction: someinstructA
    IndexCode:2 DrugName:Drug B DrugInstruction: someinstructB
    IndexCode:3 DrugName:Drug C DrugInstruction: someinstructC
    IndexCode:4 DrugName:Drug D DrugInstruction: someinstructD
    Kind Regards
    Hana

    what you want is really simple: it's a class:
    public class record {
    public byte[] name;
    public short credit;
    //no constructor means default void constructor
    //use
    class main {
    private record[] records;
    private short record_count;
    //in a method, create a record
    short rec_num = record_count++;
    records[rec_num]=new record();
    records[rec_num].credit = .....
    records[rec_num].name=new byte[16];
    JCSystem.arrayCopyNonAtomic( data..... , offset..... records[rec_num].name,16);
    //Etc
    cheat sheet:
    - no string in javacards, use byte[] arrays, and encode strings to ASCII UTF8 or whatever
    - no int except in rare cards, use shorts for 16 bits values, arrays of bytes to simulate ints
    - no pointers in java
    - struct are classes
    - byte[] arrays created with new are non volatile
    in general, cards are dumb. they only store raw byte arrays and the actual structure management is left to the host. This is a very robust and ubiquitous design, allowing reuse and simpification of on card code.
    So in a perfect world you should'nt need a class to store records. A byte array is sufficient.
    Imagine one day you want to add a new field in your record. argh!! you have to recompile/redeploy a new applet. If some millions clients already have it... fail!
    However if you only store a raw record, it's just a matter or recompiling a basic java/whatever application, not a highly embedded code :)

  • Help with a simple Javacard application

    Hi,
    I am new to Java card. We have a project in which we basically have to verify a signature(the key for this would be generated on the card) on data and then have to sign the data with another key(also generated on the card).
    My question is:
    This looks straightforward(at least on paper) and therefore would I need to use the OPEN SC library at all? Javacard alone should be able to handle this..is it not?
    Help in this direction would be greatly appreciated.
    Best

    858087 wrote:
    Hi,
    I am new to Java card. We have a project in which we basically have to verify a signature(the key for this would be generated on the card) on data and then have to sign the data with another key(also generated on the card).
    My question is:
    This looks straightforward(at least on paper) and therefore would I need to use the OPEN SC library at all? Javacard alone should be able to handle this..is it not?Java card alone will take care of it. You just have to use the javacard framework.
    Help in this direction would be greatly appreciated.You will need to learn about the following javacard packages(classses):
    javacard.security.KeyBuilder;
    javacard.security.KeyPair;
    javacard.security.RSAPrivateCrtKey;
    javacard.security.RSAPublicKey;
    javacard.security.Signature;

  • How to select Card manager on Default JavaCard simulator from NetBeans 7.2

    Hi
    I'm trying to resolve three questions
    1) to find FAQ/Manual about simulator included into 3.0.2 JavaCard Connected platform
    2) which commands for Card Manager of simulated default JavaCard are supported
    3) how to upload simple applet (ex. HelloWorld from JavaCard 3.0.2) using Card Manager applet simulated on Default javaCard Connected platfrom simulator available from NetBeans 7.2
    Thaaaanks

    From my understanding, NetBeans uses the CREF executable from the JCDK for simulation. You can check the documentation (developer guide etc) from the JCDK for more details. The CREF emulator uses a custom applet loader so it does not use standard GP commands and will be different to a real card. As for loading your applet, you should be able to run from NB and it will start your emulator and deploy your code. I do not use netbeans so cannot really comment further.
    - Shane

  • How to use javacard develoment kit 2.2.1

    Do i need to install or just unzip the folder and that will do.
    another problem is that sample coding needs to import a package call javacard.framework and i get this error when i compile.
    plz help

    Hi Fernand,
    JDBC Lookup can be done in PI 7.1 using below mentioned steps :
    1) Create a communication channel between PI and the database to connect to database.
    2) Import the table data as External Definition.
    3) In message mapping where this lookup is to be used select JDBC Lookup under Conversions and map
    4) Double Click on JDBC Lookup
    5) Select parameter and a database table (imported as the external definition). All the elements of the table will appear in the middle column. Select and move the input parameters to the left side column and the output parameters to the right side column. Click OK. 
    6) Under message mapping go to signature tab and define the parameter as channel and category as JDBC Adapter Type. 
    7) Under Operation mapping define the parameter & associate it with parameter defined in Message Mapping.
    Thanks
    Amit

  • How to get started on JavaCard 3.0 development?

    Hi,
    I wasn't able to attend JavaOne, but from what I understand, some lucky developers were able to write JavaCard 3.0 apps to compete in the contest that was held at JavaOne. So, how can I get started in JavaCard 3.0 app development? I can't find anywhere where I can download an SDK or buy compatible cards.
    Thanks,
    Bruce

    daddyhop wrote:
    I but I want to use the new features that in 3.0 that developers had access at JavaOne in order to participate in the contest. Where's the link for the stuff that folks had to play with at JavaOne?http://java.sun.com/javacard/contest/index.jsp
    http://java.sun.com/javacard/contest/download.jsp
    http://developer.gemalto.com/home/java-card-3/developer-contest/jc3bot-installation-instructions.html
    http://developer.gemalto.com/home/java-card-3/developer-contest/jc3bot-development-guide.html
    http://developer.gemalto.com/nc/forums.html
    http://javacard.vetilles.com/2008/05/08/writing-a-java-card-3-program/
    http://blogs.sun.com/javacard/entry/not_an_architecture_diagram

  • 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

  • JAVACARD development environment???

    Hello everyone
    I am a beginner of javacrad development, I built a environment like this:
    Eclipse V3.3.2
    JRE 7
    Plugin JCDE0.1
    JCDK 2.2.2
    JCOP Tools 3.1.1.b already activate
    but I found there are some errors for this environment.
    1. I can not generate CAP file both use JCOP or JCWDE even using a sample applet.
    For JCOP
    cm> upload -d "C:\Users\tang\workspace\Tang\bin\Tang_Test\javacard\Tang_Test.cap"
    jcshell: Cannot read <C:\Users\tang\workspace\Tang\bin\Tang_Test\javacard\Tang_Test.cap>: java.io.FileNotFoundException: C:\Users\tang\workspace\Tang\bin\Tang_Test\javacard\Tang_Test.cap
    cm> install -i 48656c6c6f776f726c64 -q C9#() 5448576f726c64 48656c6c6f776f726c64
    => 80 E6 0C 00 24 07 54 48 57 6F 72 6C 64 0A 48 65 ....$.THWorld.He
    6C 6C 6F 77 6F 72 6C 64 0A 48 65 6C 6C 6F 77 6F lloworld.Hellowo
    72 6C 64 01 00 02 C9 00 00 00 rld.......
    (1880 usec)
    <= 6A 88 j.
    Status: Reference data not found
    jcshell: Error code: 6a88 (Reference data not found)
    jcshell: Wrong response APDU: 6A88
    For JCWDE
    Java Card 2.2.2 Class File Converter, Version 1.3
    Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
    conversion completed with 1 errors and 0 warnings.
    error: Lan.LanHW: unsupported class file format of version 50.0.
    Does anyone know how to resolve this problem?
    Thanks a lot.

    Hi,
    For that version of JCOP tools you will be developing against JC 2.2.1 and need to set your Java compiler settings in Eclipse to 1.3 for that project. For JCWDE you will be targeting JC 2.2.2 so you can use 1.5 as the compiler version. The JDK version has nothing to do with this so you do not need a different JDK. Eclipse has its own built in compiler.
    Shane

  • How to store data,key,cert,... in javacard

    I'm newbie in javacard
    I develop it by use RMI model
    I develop to similar EMV specification but don't exactly
    EMV spec told me that data element such as KEY, CERT,COUNTER,ExpirationDate,...anything. will be keep in file , with tree structure.
    above is not importance
    I try to understand: How to save file into javacard?
    I read a lot of help and manual from sdk , this website ,forum
    and I feel it's impossible to save file (such as text file *.txt, photo file *.jpeg,*.gif) into javacard directly,
    Is my understand correct?
    I try to understand PhotoCardApplet Demo that come with sdk
    run it , have fun with it, try to understand code
    I saw the demo bring the pictures file from reader-side save into card to the "Object" of byte[]
    Is there just only one way to keep KEY,CERT,..DATA in Object in the applet?
    Can it possible to seperate these data away from applet and keep it individual? ( seperate applet , text file ,photo file ,... keep in javacard)
    And if it possible plz tell me how to do it with detailed.
    thx for every answer.

    EMV spec told me that data element such as KEY,
    CERT,COUNTER,ExpirationDate,...anything. will be
    keep in file , with tree structure.That is the file-system part of an EMV smart card. That has nothing (directly) to do with java cards. Most java cards has a file system part, too but that isn't accessible from within the java card applet.
    I try to understand PhotoCardApplet Demo that come
    with sdk
    run it , have fun with it, try to understand code
    I saw the demo bring the pictures file from
    reader-side save into card to the "Object" of
    byte[]
    Is there just only one way to keep KEY,CERT,..DATA
    in Object in the applet?
    Can it possible to seperate these data away from
    applet and keep it individual? ( seperate applet ,
    text file ,photo file ,... keep in javacard)
    No, loading data into the memory which belongs to your java card applet instance makes the data become a part of the applet. If you delete the applet all stored data will be deleted, too.
    You can only separate different objects within your applet by using separate byte-arrays or other java card objects.
    Jan

Maybe you are looking for

  • Mismatch General Ledger Module VS Fixed Asset Module

    Several amount differences arise when checking the posting totals in GL versus Asset history sheet (transaction S_ALR_87011990, 'depreciation posted' set to 'yes'). Year 2007 is not closed yet, and after executing transaction AFAR some differences di

  • Send report as attachment

    I have to set up SSRS report in such a way that each report has to go to different person based on ID. Basically like one report has 10 pages each page assigned to 10 different persons. How can we send each page as an attachment email dynamically whe

  • S_AHR_61016401

    Hello there , There seem to be an error with the set up with this EPN number. When running this report S_AHR_61016401 with our cost centers this EPN does not come out in the reports . But if I take the cost centers away and just search by EPN, then i

  • Business Objects Implementation

    Hi Gurus, We are looking at implementing Business Objects for the purpose of using Dashboards at our company. Please help with the process of implementation. Regards, Kennedy.

  • Airport Express and DVD's

    Hi, I wish to use my mac mini as a dvd player. If i use the airport express with its digital out, with my stereo that is surround sound (dolby) and digital in, will the surround sound go through airport express?