PKCS#11 Emulation on JavaCards

For those who don't know: PKCS #11 is the Cryptographic Token Interface Standard, an interface which is (amongs other means) used by crypthographic smart cards.
PKCS #11 contains standard crypto functions like encrypt/decrypt, signatures and MAC checksums.
Any idea if it is possible for a JavaCard applet to emulate the pkcs11 standard?
or maybe:
What approach would you chose to emulate pkcs11? Does this make sense or should one better create his own "proprietary" interface to the javacard crypto functions and implement his own keystore?

I would recommend that you submit a formal Support request as this is a detailed problem.
From: Adobe Forums <[email protected]<mailto:[email protected]>>
Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Date: Wed, 30 Nov 2011 21:02:08 -0800
To: Leonard Rosenthol <[email protected]<mailto:[email protected]>>
Subject: Custom PKCS#11 Driver on Mac
Custom PKCS#11 Driver on Mac
created by Dirtmal<http://forums.adobe.com/people/Dirtmal> in Acrobat SDK - View the full discussion<http://forums.adobe.com/message/4056253#4056253

Similar Messages

  • 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

  • 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

  • SATSA Card Emulator App communication

    Greetings,
    I know that probably this questions has been asked a million of times, but i just cant get it done and i've searched through google.
    I have my midlet with with piece of code:
    private final String slot0ApduAid = "apdu:0;target=f7.22.20.94.5a";
    private APDUConnection apduConnection0;
    apduConnection0 = (APDUConnection)Connector.open(slot0ApduAid);I have my JavaCard Applet loaded into the emulator
       public void process(APDU apdu) {
            byte[] buffer = apdu.getBuffer();
            if (apdu.isISOInterindustryCLA()) {
                if (buffer[ISO7816.OFFSET_INS] == (byte) (0xA4)) {
                    return;
                ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
            if (buffer[ISO7816.OFFSET_CLA] != Wallet_CLA) {
                ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
            switch (buffer[ISO7816.OFFSET_INS]) {
                      .........The problem the midlet never gets to open the connection, like when you open a socket connection and stays blocked up until the other side answer.
    In the emulator i send the list command and it shows me
    listLoaded Bundles/Libraries:
        SatsaCard [Classic Applet Bundle]
    Created Instances:
        SatsaCard: //aid/F72220945A/C0
    >However when i stop the card emulator the midlets shows the following error log:
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: Reset failed
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: javacall_carddevice_reset: can't connect to server
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: Reset failed
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: javacall_carddevice_reset: can't connect to server
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: Reset failed
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: javacall_carddevice_reset: can't connect to server
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: Reset failed
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: javacall_carddevice_reset: can't connect to server
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: Reset failed
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: javacall_carddevice_reset: can't connect to server
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: Reset failed
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: javacall_carddevice_reset: can't connect to server
    [ERRR] [carddevice_simu] CARDDEVICE ERROR: Reset failed
    javacall_lifecycle_state_changed() lifecycle: event is JAVACALL_LIFECYCLE_MIDLET_SHUTDOWNstatus is JAVACALL_OKApparently the midlet did was connected with the card .....
    Also, when i do the following change in the midlet:
    java.lang.IllegalArgumentException: Invalid AIDI dont know what seems to be the problem....

    Hi,
    Thank you in advance for your atention.
    I'm 1 step before you
    my emulator doesn't work because using
    securityElementID = new String("WIM 1.01 SATSA RI");
    midlet emulator return my prompt message and
    on top say
    WIN Application not found
    Did you solve problem?
    please help me
    Thank you again
    Matteo

  • [Javacard] Deploy code to a javacard of type gp211

    Hey i have probleme to debloy to real java card, the code works in the emulator i have instal in netbeans but not in a real card, when i try it returns 6e00
    My card is of type gp211, card reader is acs acr38 and iam using Netbeans IDE 7.4 and GPshell 1.4.4
    My Script for gpshell is :
    mode_211
    enable_trace
    establish_context
    card_connect
    select -AID a000000003000000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    delete -AID a00000006203010c0101
    delete -AID a00000006203010c01
    install -file Wallscript.cap -nvDataLimit 2000 -instParam 00 -priv 2
    card_disconnect
    release_context
    And my code is :
    package classicapplet1;
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.OwnerPIN;
    public class WallScript extends Applet {
        /* constants declaration */
        // code of CLA byte in the command APDU header
        final static byte Wallet_CLA = (byte) 0x80;
        final static byte staticpin[]={0x01,0x02,0x03,0x04,0x05};
        // codes of INS byte in the command APDU header
        final static byte VERIFY = (byte) 0x20;
        final static byte CREDIT = (byte) 0x30;
        final static byte DEBIT = (byte) 0x40;
        final static byte GET_BALANCE = (byte) 0x50;
        // maximum balance
        final static short MAX_BALANCE = 0x7FFF;
        // maximum transaction amount
        final static byte MAX_TRANSACTION_AMOUNT = 127;
        // maximum number of incorrect tries before the
        // PIN is blocked
        final static byte PIN_TRY_LIMIT = (byte) 0x03;
        // maximum size PIN
        final static byte MAX_PIN_SIZE = (byte) 0x08;
        // signal that the PIN verification failed
        final static short SW_VERIFICATION_FAILED = 0x6300;
        // signal the the PIN validation is required
        // for a credit or a debit transaction
        final static short SW_PIN_VERIFICATION_REQUIRED = 0x6301;
        // signal invalid transaction amount
        // amount > MAX_TRANSACTION_AMOUNT or amount < 0
        final static short SW_INVALID_TRANSACTION_AMOUNT = 0x6A83;
        // signal that the balance exceed the maximum
        final static short SW_EXCEED_MAXIMUM_BALANCE = 0x6A84;
        // signal the the balance becomes negative
        final static short SW_NEGATIVE_BALANCE = 0x6A85;
        OwnerPIN pin;
        short balance;
        private WallScript(byte[] bArray, short bOffset, byte bLength) {
            pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
            byte iLen = bArray[bOffset]; // aid length
            bOffset = (short) (bOffset + iLen + 1);
            byte cLen = bArray[bOffset]; // info length
            bOffset = (short) (bOffset + cLen + 1);
            byte aLen = bArray[bOffset]; // applet data length
            pin.update(staticpin,(short)0,(byte)5);
            register();
        } // end of the constructor
        public static void install(byte[] bArray, short bOffset, byte bLength) {
            new WallScript(bArray, bOffset, bLength);
        public boolean select() {
            if (pin.getTriesRemaining() == 0) {
                return false;
            return true;
        public void deselect() {
            // reset the pin value
            pin.reset();
        public void process(APDU apdu) {
            byte[] buffer = apdu.getBuffer();
            if (apdu.isISOInterindustryCLA()) {
                if (buffer[ISO7816.OFFSET_INS] == (byte) (0xA4)) {
                    return;
                ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
            if (buffer[ISO7816.OFFSET_CLA] != Wallet_CLA) {
                ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
            switch (buffer[ISO7816.OFFSET_INS]) {
                case GET_BALANCE:
                    getBalance(apdu);
                    return;
                case DEBIT:
                    debit(apdu);
                    return;
                case CREDIT:
                    credit(apdu);
                    return;
                case VERIFY:
                    verify(apdu);
                    return;
                default:
                    ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        private void credit(APDU apdu) {
            if (!pin.isValidated()) {
                ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
            byte[] buffer = apdu.getBuffer();
    U
            byte numBytes = buffer[ISO7816.OFFSET_LC];
            byte byteRead = (byte) (apdu.setIncomingAndReceive());
            if ((numBytes != 1) || (byteRead != 1)) {
                ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
            byte creditAmount = buffer[ISO7816.OFFSET_CDATA];
            // check the credit amount
            if ((creditAmount > MAX_TRANSACTION_AMOUNT) || (creditAmount < 0)) {
                ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
            if ((short) (balance + creditAmount) > MAX_BALANCE) {
                ISOException.throwIt(SW_EXCEED_MAXIMUM_BALANCE);
            balance = (short) (balance + creditAmount);
        private void debit(APDU apdu) {
            if (!pin.isValidated()) {
                ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
            byte[] buffer = apdu.getBuffer();
            byte numBytes = (buffer[ISO7816.OFFSET_LC]);
            byte byteRead = (byte) (apdu.setIncomingAndReceive());
            if ((numBytes != 1) || (byteRead != 1)) {
                ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
            byte debitAmount = buffer[ISO7816.OFFSET_CDATA];
            if ((debitAmount > MAX_TRANSACTION_AMOUNT) || (debitAmount < 0)) {
                ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
            if ((short) (balance - debitAmount) < (short) 0) {
                ISOException.throwIt(SW_NEGATIVE_BALANCE);
            balance = (short) (balance - debitAmount);
        private void getBalance(APDU apdu) {
            if (!pin.isValidated()) {
                ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
            byte[] buffer = apdu.getBuffer();
            short le = apdu.setOutgoing();
            if (le < 2) {
                ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
            apdu.setOutgoingLength((byte) 2);
            buffer[0] = (byte) (balance >> 8);
            buffer[1] = (byte) (balance & 0xFF);
            apdu.sendBytes((short) 0, (short) 2);
        } // end of getBalance method
        private void verify(APDU apdu) {
            byte[] buffer = apdu.getBuffer();
            byte byteRead = (byte) (apdu.setIncomingAndReceive());
            if (pin.check(buffer, ISO7816.OFFSET_CDATA, byteRead) == false) {
                ISOException.throwIt(SW_VERIFICATION_FAILED);
    Need help pls

    Hello, we need apdu traces. "It doesn't work" is not enough. Thanks.

  • Some questions about javacard 2.1.1 and smartcardio

    Hello i have some question about java card 2.1.1 and the smartcardio package.
    1.) I want to sign a message with the Signature.ALG_RSA_SHA_PKCS1 algorithm. I use the following code in the applet to sign the message:
    final static byte P1_CREATION_MODE = (byte) 0x01;
    final static byte INS_SIGN_MODE = (byte) 0x60;
    final static byte SmartCard_CLA = (byte) 0xB0;
    private void signMessage(APDU apdu) {
            byte[] buffer = apdu.getBuffer();
            byte byteRead = (byte) (apdu.setIncomingAndReceive());
            signature.init(privateKey, Signature.MODE_SIGN);
            short length = signature.sign(buffer, ISO7816.OFFSET_CDATA, byteRead, buffer, (short) 0);
            apdu.setOutgoingLength((short) length);
            apdu.sendBytesLong(buffer, (short) ISO7816.OFFSET_CDATA, (short) length);
            apdu.setOutgoing();
        }On the host side I use the following code to connect to the card and to send the sign apdu:
    if (TerminalFactory.getDefault().terminals().list().size() == 0) {
                LOGGER.log(Level.SEVERE, "No reader present");
                throw new NoSuchCardReader();
            /* Select the first terminal*/
            CardTerminal terminal = TerminalFactory.getDefault().terminals().list().get(0);
            /* Is a card present? */
            if (!terminal.isCardPresent()) {
                LOGGER.log(Level.SEVERE, "No Card present!");
                throw new NoSuchCard();
            /* Set the card protocol */
         Card card = terminal.connect("*");
            ATR atr = card.getATR();
            LOGGER.fine(getHexString(atr.getBytes()));
            LOGGER.fine(getHexString(atr.getHistoricalBytes()));
            CardChannel channel = card.getBasicChannel();
            CommandAPDU cmd = new CommandAPDU((byte) 0xb0, (byte) 0x60, (byte) 0x01, (byte) 0x00, new String("datadatdatadata").getBytes(), (byte) 0x40);
         ResponseAPDU response = channel.transmit(cmd);
            card.disconnect(false);But this does not work and i got the following error
    javax.smartcardio.CardException: sun.security.smartcardio.PCSCException: Unknown error 0x8010002f
            at sun.security.smartcardio.ChannelImpl.doTransmit(ChannelImpl.java:202)
            at sun.security.smartcardio.ChannelImpl.transmit(ChannelImpl.java:73)
            at de.upb.client.smartmeter.SmartMeter.initSmartCardApplet(SmartMeter.java:114)
            at de.upb.client.smartmeter.SmartMeterApplikation.main(SmartMeterApplikation.java:39)
    Caused by: sun.security.smartcardio.PCSCException: Unknown error 0x8010002f
            at sun.security.smartcardio.PCSC.SCardTransmit(Native Method)
            at sun.security.smartcardio.ChannelImpl.doTransmit(ChannelImpl.java:171)
            ... 3 more2.) 3Des encryption
    I want to use the 3Des algorithm to encrypt my data. I use
    keyDES = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES,
                        KeyBuilder.LENGTH_DES3_2KEY, false);
    cipherDES = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M2, false);But i do not know what is the aquivalent on the host side??
    3.) Another problem is that i am not able to send the modulus of a public key from the host applikation to the smard card
    new CommandAPDU((byte) 0xb0, (byte) 0x20, (byte) 0x01, (byte) 0x00, modulus.toByteArray()); // create the apdu
    // the method in the applet
    private void setServerKeyMod(APDU apdu) {
            byte[] buffer = apdu.getBuffer();
            try {
                byte byteRead = (byte) (apdu.setIncomingAndReceive());
                short off = ISO7816.OFFSET_CDATA;
                // strip of any integer padding
                if (buffer[off] == 0) {
                    off++;
                    byteRead--;
                publicKeyServer.setModulus(buffer, off, byteRead);
            } catch (APDUException ex) {
                ISOException.throwIt((short) (SW_APDU_EXCEPTION + ex.getReason()));
        }The error code is 6700
    4.) My last problem ist, that i am not able to use a value bigger than 0x7F as the ne field in the apducommand, because i get the following error
    CommandAPDU((byte) 0xb0, (byte) 0x60, (byte) 0x01, (byte) 0x00, data, (byte) 0xff);
    java.lang.IllegalArgumentException: ne must not be negative
            at javax.smartcardio.CommandAPDU.<init>(CommandAPDU.java:371)
            at javax.smartcardio.CommandAPDU.<init>(CommandAPDU.java:252)I thought that it this should be possible in order to use all the bytes of the response apdu.
    If you need more code to help please let me know.
    Cheers
    Edited by: 858145 on 06.07.2011 08:23

    2) What is PKCS? what is the difference between
    PKCS#11 and PKCS#15??PKCS is the abbreviation of "Public-Key Cryptography Standards"
    PKCS #11: Cryptographic Token Interface Standard
    See http://www.rsasecurity.com/rsalabs/node.asp?id=2133
    PKCS #15: Cryptographic Token Information Format Standard
    http://www.rsasecurity.com/rsalabs/node.asp?id=2141
    If you want to use yor smartcard as secure token it doesn't have to be a JavaCard.
    BTW: I don't remember a way to access PKCS#15 tokens on a JavaCard from within an oncard JavaCard program. If you want to use keys in your oncard program, you have to transfer it onto the card or generate it oncard and export the public key by your own oncard/offcard code.
    Jan

  • Beginner basics to deploy a JavaCard applet

    I've been struggling with the JavaCard 2.2 Dev Kit for a while now. I've read tons of material on writing JavaCard applets and OpenCard host apps, and feel I have a firm grasp of that. My problem now is in how to get the applet java file into an emulator, and then get a host app running that will communicate with the emulated card.
    I've read the documentation and demos that came with the Dev Kit but nowhere does it simply list the big picture procedure for deploying a JC applet, nor for how to communicate with an emulated card, nor which emulator to use.
    The PDF files included are filled with references to CAP, JCWDE, JCA, CREF, etc, etc, ad nauseum, all of which are poorly explained, or simply not explained at all.
    I just want something like this:
    1) Compile the applet's java file
    2) Run A to generate a B file
    3) Run C to start the card emulator
    4) Do X to install your B file into the emulated card
    5) Do Y to have your host program talk to the emulated card
    etc
    etc
    etc
    Can anyone help?

    all of which are poorly explained,
    Read the cJDK user guide that comes with the kit. The samples and how to use the Sun JC tools are explained in detail there. Chapter 4 is Running applets in the simulated environment. Don't jump around the document but read it in order.

  • JCOP emulator insert card event

    Hello,
    I�m connecting remotelly to the IBM JCOP Tools emulator. I�m using the following demo code but the application waits for ever for a card inser event. Because this is an emulator I don�t know how to do an insert card...
    Any ideas?
    Thanks a lot,
    Gonzalo
         private static void ejecuta()
              try
                   // Initialize OCF
                   SmartCard.start();
                   // Wait for a smart card
                   CardRequest cr = new CardRequest(CardRequest.NEWCARD, null,
                                                           OCFCardAccessor.class);
    // HERE IT WAITS FOR EVER!!!!
                   SmartCard myCard = SmartCard.waitForCard(cr);
                   // Get an OCFCardAccessor for Java Card RMI
                   CardAccessor ca = (CardAccessor)
                        myCard.getCardService(OCFCardAccessor.class, true);
                   // Create a Java Card RMI instance
                   JavaCardRMIConnect jcRMI = new JavaCardRMIConnect(ca);
                   // Create a Java Card Proxy Factory that is used for dynamic
                   // proxy generation.
                   CardObjectFactory factory = new JCCardProxyFactory(ca);
                   // select the Java Card applet
                   jcRMI.selectApplet(MY_APPLET_AID, factory);
                   // Get the initial reference
                   Purse purseInterface =
                        (Purse) jcRMI.getInitialReference();
                   if(purseInterface == null)
                        throw new Exception("Received null instead of the initial ref");
                   // Invoke the remote getBalance() method
                   short balance = purseInterface.getBalance();
                   System.out.print("balance: " + balance);
              catch(UserException e)

    Hello Jan,
    I told you the wrong behabeur... The waitForCard is not the problem the problem is some place else.
    Thanks for your help, this is my first JavaCard program and I�m really lost...
    This is my opencard.properties:
    # Open Card Service
    OpenCard.services = opencard.opt.util.PassThruCardServiceFactory
    OpenCard.terminals = jcopterminal.WrapperFactory|JCOPTerminal|Remote|localhost:8050
    # TRACE configuration #
    OpenCard.trace = opencard:8
    This is the log of the error I�m getting:
    ERROR
    INFO ] opencard.core.service.CardServiceRegistry.getCardServiceClass
    --- message no CardService for class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [INFO     ] opencard.core.service.CardServiceRegistry.isCardRequestSatisfied
    --- message requested CardService class class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor not supported for opencard.core.terminal.CardID@1016632 ATR: 3B F8 95 00 00 81 31 FE 45 00 73 C8 40 13 00 90
    00 1E
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [INFO     ] opencard.core.service.CardServiceRegistry.getSmartCard
    --- message CardRequest opencard.core.service.CardRequest@1865b28 ANYCARD
    service = class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor cannot be satisfied with opencard.core.terminal.CardID@1016632 ATR: 3B F8 95 00 00 81 31 FE 45 00 73 C8 40 13 00 90
    00 1E
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    FULL LOG
    [DEBUG    ] opencard.core.service.SmartCard.getRegistryEntry
    --- message tag OpenCard.terminals = jcopterminal.WrapperFactory|JCOPTerminal|Remote|localhost:8050
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.SmartCard
    [DEBUG    ] opencard.core.terminal.CardTerminal.<init>
    --- message (JCOPTerminal, Remote, localhost:8050)
    --- thread Thread[main,5,main]
    --- source class opencard.core.terminal.CardTerminal
    [DEBUG    ] opencard.core.service.CardServiceRegistry.<init>
    --- message instantiating
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.CardServiceRegistry
    [DEBUG    ] opencard.core.service.SmartCard.getRegistryEntry
    --- message tag OpenCard.services = opencard.opt.util.PassThruCardServiceFactory
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.SmartCard
    [DEBUG    ] opencard.core.service.CardServiceFactory.<init>
    --- message instantiating
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.CardServiceFactory
    [DEBUG    ] opencard.opt.service.OCF11CardServiceFactory.<init>
    --- message instantiating
    --- thread Thread[main,5,main]
    --- source class opencard.opt.service.OCF11CardServiceFactory
    [DEBUG    ] opencard.core.service.CardServiceRegistry.add
    --- message opencard.opt.util.PassThruCardServiceFactory@92bbba
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6
    [DEBUG    ] opencard.core.service.SmartCard.<start>
    --- message finished
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.SmartCard
    [DEBUG    ] opencard.core.service.SmartCard.waitForCard
    --- message passing request opencard.core.service.CardRequest@1865b28 ANYCARD
    service = class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor to CardServiceRegistry
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.SmartCard
    [DEBUG    ] opencard.core.service.CardWaiter.<init>
    --- message Request: opencard.core.service.CardRequest@1865b28 ANYCARD
    service = class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.CardWaiter
    [DEBUG    ] opencard.core.service.CardWaiter.cardInserted
    --- message CTEvent: opencard.core.event.CardTerminalEvent[source=jcopterminal.JCOPTerminal@4ac00c
    + name JCOPTerminal
    + type Remote
    + addr localhost:8050]
    ---source jcopterminal.JCOPTerminal@4ac00c
    + name JCOPTerminal
    + type Remote
    + addr localhost:8050
    ---id 1
    card inserted in slot 0
    terminal jcopterminal.JCOPTerminal@4ac00c
    + name JCOPTerminal
    + type Remote
    + addr localhost:8050
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.CardWaiter
    [DEBUG    ] opencard.core.service.CardServiceRegistry.getSmartCard
    --- message CTEvent opencard.core.event.CardTerminalEvent[source=jcopterminal.JCOPTerminal@4ac00c
    + name JCOPTerminal
    + type Remote
    + addr localhost:8050]
    ---source jcopterminal.JCOPTerminal@4ac00c
    + name JCOPTerminal
    + type Remote
    + addr localhost:8050
    ---id 1
    card inserted in slot 0
    terminal jcopterminal.JCOPTerminal@4ac00c
    + name JCOPTerminal
    + type Remote
    + addr localhost:8050
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [DEBUG    ] jcopterminal.JCOPTerminal.openSlotChannel
    --- message for slot #0
    --- thread Thread[main,5,main]
    --- source jcopterminal.JCOPTerminal@4ac00c
    + name JCOPTerminal
    + type Remote
    + addr localhost:8050
    [DEBUG    ] jcopterminal.JCOPTerminal.openSlotChannel
    --- message new SlotChannel is opencard.core.terminal.SlotChannel@9e29fb
    + state open
    --- thread Thread[main,5,main]
    --- source jcopterminal.JCOPTerminal@4ac00c
    + name JCOPTerminal
    + type Remote
    + addr localhost:8050
    [DEBUG    ] opencard.core.service.CardServiceRegistry.allocateCardServiceScheduler
    --- message instantiating CardServiceScheduler
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [DEBUG    ] opencard.core.service.CardServiceScheduler.<init>
    --- message slotChannel opencard.core.terminal.SlotChannel@9e29fb
    + state open
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.CardServiceScheduler
    [DEBUG    ] opencard.core.service.CardChannel.<init>
    --- message (opencard.core.terminal.SlotChannel@9e29fb
    + state open)
    --- thread Thread[main,5,main]
    --- source class opencard.core.service.CardChannel
    [DEBUG    ] opencard.core.service.CardServiceRegistry.getCardServiceClass
    --- message for class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor and opencard.core.terminal.CardID@1016632 ATR: 3B F8 95 00 00 81 31 FE 45 00 73 C8 40 13 00 90
    00 1E
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [DEBUG    ] opencard.core.service.CardServiceRegistry.getCardServiceClass
    --- message checking opencard.opt.util.PassThruCardServiceFactory@92bbba
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [DEBUG    ] opencard.opt.util.PassThruCardServiceFactory.getClassFor
    --- message checking class opencard.opt.util.PassThruCardService
    --- thread Thread[main,5,main]
    --- source opencard.opt.util.PassThruCardServiceFactory@92bbba
    [DEBUG    ] opencard.core.service.CardServiceRegistry.getCardServiceClass
    --- message factory opencard.opt.util.PassThruCardServiceFactory@92bbba produced null
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [INFO     ] opencard.core.service.CardServiceRegistry.getCardServiceClass
    --- message no CardService for class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [INFO     ] opencard.core.service.CardServiceRegistry.isCardRequestSatisfied
    --- message requested CardService class class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor not supported for opencard.core.terminal.CardID@1016632 ATR: 3B F8 95 00 00 81 31 FE 45 00 73 C8 40 13 00 90
    00 1E
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [INFO     ] opencard.core.service.CardServiceRegistry.getSmartCard
    --- message CardRequest opencard.core.service.CardRequest@1865b28 ANYCARD
    service = class com.sun.javacard.ocfrmiclientimpl.OCFCardAccessor cannot be satisfied with opencard.core.terminal.CardID@1016632 ATR: 3B F8 95 00 00 81 31 FE 45 00 73 C8 40 13 00 90
    00 1E
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceRegistry@162dbb6++ registered factory opencard.opt.util.PassThruCardServiceFactory@92bbba
    [DEBUG    ] opencard.core.service.CardServiceScheduler.closeDown
    --- message closing down scheduler
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardServiceScheduler@b8deef, is alive
    [DEBUG    ] opencard.core.service.CardChannel.closeFinal
    --- message closing for good
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardChannel@1342ba4, not open, not jammed
    [DEBUG    ] opencard.core.service.CardChannel.close
    --- message CardChannel closed
    --- thread Thread[main,5,main]
    --- source opencard.core.service.CardChannel@1342ba4, not open, not jammed
    [DEBUG    ] opencard.core.terminal.SlotChannel.close
    --- message closing channel
    --- thread Thread[main,5,main]
    --- source opencard.core.terminal.SlotChannel@9e29fb
    + state open
    -----------------------------------------------------------------------------------------------

  • How to get Current Location in a Android Emulator using Flex

    Hi
    In the following code I am able to plot the Location using Latitude and Longitude but the requirement is
    in an Android Emulator on launch of the application I need google map to display the users current location,
    How can this be achieved ??? I tried to get the Latitude and Longitude of the current position using
    geoLocation class by I am not able to get that working,
    <?xml version="1.0" encoding="utf-8"?>
    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark" title="Home">
        <s:layout>
            <s:VerticalLayout />
        </s:layout>
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import com.google.maps.LatLng;
                import com.google.maps.MapEvent;
                import com.google.maps.MapType;
                import com.google.maps.controls.PositionControl;
                import com.google.maps.controls.ZoomControl;
                import flash.sensors.Geolocation;
                private var myGeo:Geolocation;
                protected function showBtn_clickHandler(event:MouseEvent):void
                    if(Geolocation.isSupported == 'true')
                        myGeo = new Geolocation();
                        myGeo.setRequestedUpdateInterval(100);
                        myGeo.addEventListener(GeolocationEvent.UPDATE, onUpdate);
                    else
                        myTextArea.text = "Device Not Supported";
                private function onUpdate(event:GeolocationEvent):void
                    myTextArea.text += "Hi"+ "/n"+ event.latitude.toString() + "/n" +
                        event.longitude.toString();
                protected function myMap_mapevent_mapreadyHandler(event:MapEvent):void
                    myMap.setCenter(new LatLng(24,58),9,MapType.NORMAL_MAP_TYPE);
                    myMap.addControl(new ZoomControl);
                    myMap.addControl(new PositionControl);
            ]]>
        </fx:Script>
        <s:Button id="showBtn" label="Show" click="showBtn_clickHandler(event)"/>
        <s:TextArea id="myTextArea" width="100%" height="50%" />
        <maps:Map id="myMap" width="100%" height="50%"
                  xmlns:maps="com.google.maps.*"
                  sensor="true"
                  key="ABQIAAAA2Fwy6HLBheYSAWRBEZKwEhRLum8XdHegG17d4EymNgK0o7h2qRRWVBVQywiGHEiGtKahjfGW8xxc RA"
                  mapevent_mapready="myMap_mapevent_mapreadyHandler(event)"
                  url="http://www.xyz.com"/>
    </s:View>

    Geolocation isn't supported in the Emulator. You'll have to set up a test case that gives the geolocation without relying on the Emulator.

  • Unable to raise button Event in BlackBerry Emulator

    Hi All,
    I've created a WebDynpro Application which invokes a BAPI on click of a button(or Link to Action). This Application s running fine on IE.
    I wanted t port this on a Blackberry device. I'm testing on a BlackBerry emulator. The first view is getting displayed properly, but I'm unable to click the Button which is displayed.
    How to raise this event on the BlackBerry Emulator?
    Thanks and regards
    RK

    Hi,
    Thanks for looking at my post.
    @Heidi: I had already gone thru the link.
    @Stefanie: I am using BlackBerry Emulator for model 7520/7920. There is no wheel(I guess I didn't understand you properly). Yes I clicked on enter button.
    I'm a bit confused with the Button. In manual they said that the property 'Design' is ignored for Mobile Devices and at the same time they say if the Design is emphasized then you will get a softkey. I tried with Design Standard(which is default) and also Emphasized. I dont see any Softkey. I really don't know how a softkey looks like. I guess there will be a extra icon or button on the screen. But I don't see any.
    Thanks and regards
    RK

  • HTTPS connection from emulator

    Hello friends,
    I want to send https request from emulator from my application..
    when I am trying to send HTTPS request from emulator(wtk22's default emulator) it gives error
    javax.microedition.io.ConnectionNotFoundException: TCP open
         at com.sun.midp.io.j2me.socket.Protocol.connect(+99)
         at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+52)
         at com.sun.midp.io.j2me.socket.Protocol.openPrim(+108)
         at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+14)
         at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+8)
         at com.sun.midp.io.j2me.https.Protocol.connect(+167)
         at com.sun.kvem.io.j2me.https.Protocol.connect(+4)
         at com.sun.midp.io.j2me.http.Protocol.streamConnect(+57)
         at com.sun.kvem.io.j2me.https.Protocol.streamConnect(+4)
         at com.sun.midp.io.j2me.http.Protocol.startRequest(+12)
         at com.sun.midp.io.j2me.http.Protocol.sendRequest(+38)
         at com.sun.midp.io.j2me.http.Protocol.sendRequest(+6)
         at com.sun.midp.io.j2me.http.Protocol.getResponseCode(+8)
         at bd.a(+97)
         at cj.run(+155)
    XML Response: null
    * Application is working fine on device/Mobile.......i.e.from mobile i can send https request successfully ...*
    so wts the problem with emulator...can anybody help me?
    Thanks in advance
    Regards,
    Parag

    Could you explain how transport protocol influences certificate exchange during SSL session?

  • XAP Applications are not getting published in Windows Phone 8.1 Emulator

    I've SCCM + Intune integrated environment (trail version of Intune). Enrolled Windows phone 8.1 (emulator) device into the infrastructure. 
    I'm able to login to company portal and can see the devices associated with my user name in the company portal however I'm not able to publish any of the apps. It says your query didn't return any results :(
    I tried all the following types of apps (Windows apps in the windows store, Windows Phone app package and Windows phone app package in the windows phone store) but nothing getting published :( any clue ?
    Anoop C Nair (My Blog www.AnoopCNair.com)
    - Twitter @anoopmannur -
    FaceBook Forum For SCCM

    Yes, at last issue got resolved :)
    http://anoopcnair.com/2014/11/11/xap-applications-published-windows-phone-8-1-intune-integrated-sccm-2012-r2/
    Anoop C Nair (My Blog www.AnoopCNair.com)
    - Twitter @anoopmannur -
    FaceBook Forum For SCCM

  • Visual Studio 2013 WP Emulator not working after adding more RAM

    After a few days I installed VS 2013 on my laptop which had 3GB RAM and got notified by visual studio that I need at least 4 GB for hardware virtualization. Now I have 6GB RAM and Hyper-V restarted and VS still doesn't recognize my new RAM and doesn't give
    me an option to run the WP emulator.
    Did any of you had a problem/solution with this?

    Run MSInfo32.exe and post the System Summary results.
    Also check them against the system requirements for Windows Phone emulators:
    http://msdn.microsoft.com/en-us/library/windows/apps/ff626524(v=vs.105).aspx
    Eric Fleck, Windows Store and Windows Phone Developer Support. If you would like to provide feedback or suggestions for future improvements to the Windows Phone SDK please go to http://wpdev.uservoice.com/ where you can post your suggestions and/or cast
    your votes for existing suggestions.

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

Maybe you are looking for

  • Extending the material to multiple plants

    Hello Experts, I am trying to extend the material to multiple plants and storage locations based on the source material storage locations. I am retrieving the data from mard and marc table to check whether that material is already got extended to the

  • Blank page after file upload

    Hello, we are facing problem with Apex Listener 2.0 connecting to Apex 4.1.1. The Apex Listener is deployed on Tomcat. Almost everything works correctly, with one exception - uploading files. After uploading file, blank page with url http://server:80

  • Any options for sleep indicator LED?

    I was looking at my new MBP and I started wondering if it would be possible to reuse the Sleep LED indicator while the system was not sleeping. For example, while the system is awake, couldn't we reuse the LED to indicate WiFi activity or even HDD ac

  • Code formatter breaking my literals asunder

    The code formatter should respect my literal new lines rather than breaking my literals asunder, ||ltrim(sys_connect_by_path("Customer Name", ': for one can not use a function such as chr(10) in sys_connect_by_path.

  • Help with downloaded install wizard.

    Hello, I just got a WRT54G2.  My computer's CD drives don't work so I am trying to install with the downloadable wizard. I downloaded it from this page: http://www.linksysbycisco.com/US/en/support/WRT54G2/download What I get is a .iso file and I have