Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:18:49+00:00 2026-05-31T04:18:49+00:00

i am writing a sim card applet and i need to store data on

  • 0

i am writing a sim card applet and i need to store data on sim card.

but i didnt do it.
i found an example and use it but data disappear always when simulator restart.
i use “cmdPUTDATA(apdu);” method for save data and i use “cmdGETDATA(apdu);” method for save data.

here is my code and response;

     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);
        }

        switch (buffer[ISO7816.OFFSET_INS]) {
            case INS_GET_BALANCE:
                getBalance(apdu);
                return;
            case INS_CREDIT:
                credit(apdu);
                return;
            case INS_CHARGE:
                charge(apdu);
                return;
//            case INS_SELECT:                      // it is a SELECT FILE instruction
//                cmdSELECT(apdu);
//                break;
//            case INS_VERIFY:                      // it is a VERIFY instruction
//                cmdVERIFY(apdu);
//                break;
//            case INS_PUTDATA:                     // it is a PUT DATA instruction
//                cmdPUTDATA(apdu);
//                break;
//            case INS_GETDATA:                     // it is a GET DATA instruction
//                cmdGETDATA(apdu);
//                break;
            default:
                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }

//    @TransactionType(REQUIRED)
    //synchronized 
    private void credit(APDU apdu) {

        byte[] buffer = apdu.getBuffer();
        byte numBytes = buffer[ISO7816.OFFSET_LC];
        byte byteRead = (byte) (apdu.setIncomingAndReceive());

        if ((numBytes != 2) || (byteRead != 2)) {
            ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        }

        short creditAmount = (short) ((short) (buffer[ISO7816.OFFSET_CDATA] << (short) 8) | (buffer[ISO7816.OFFSET_CDATA + 1]));

        if ((creditAmount > MAX_BALANCE) || (creditAmount < (short) 0)) {
            ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
        }

        if ((short) (balance + creditAmount) > MAX_BALANCE) {
            ISOException.throwIt(SW_MAX_BALANCE_EXCEEDED);
        }
        JCSystem.beginTransaction();
        balance = (short) (balance + creditAmount);
        JCSystem.commitTransaction();
    }

    private void getBalance(APDU apdu) {
        byte[] buffer = apdu.getBuffer();
        buffer[0] = (byte) (balance >> (short) 8);
        buffer[1] = (byte) (balance & (short) 0x00FF);
        //apdu.setOutgoingLength((byte) 2);        
        //apdu.sendBytes((short) 0, (short) 2);
        apdu.setOutgoingAndSend((short)0, (short)2);
    }

    private void charge(APDU apdu) {        
        byte[] buffer = apdu.getBuffer();
        byte numBytes = buffer[ISO7816.OFFSET_LC];
        byte byteRead = (byte) (apdu.setIncomingAndReceive());

        if ((numBytes != 2) || (byteRead != 2)) {
            ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        }

        short chargeAmount = (short) ((short) (buffer[ISO7816.OFFSET_CDATA] << (short) 8) | (buffer[ISO7816.OFFSET_CDATA + 1]));

        if ((chargeAmount > MAX_BALANCE) || (chargeAmount < (short) 0)) {
            ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
        }

        if ((short) (balance - chargeAmount) < 0) {
            ISOException.throwIt(SW_MIN_BALANCE_EXCEEDED);
        }
        JCSystem.beginTransaction();
        balance = (short) (balance - chargeAmount);
        JCSystem.commitTransaction();
    }

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:18:50+00:00Added an answer on May 31, 2026 at 4:18 am

    constructor method and my other method is here. between the “beginTransaction” and “commitTransaction” code, goto EEPROM persitent data. But it run only classic applet(java card api 3.0), it doesnt run Extendet Applet.

     private Akbil_Classic(byte[] bArray, short bOffset, byte bLength) {
                memory = new byte[SIZE_MEMORY];
        }
    
    private void charge(APDU apdu) {        
        byte[] buffer = apdu.getBuffer();
        byte numBytes = buffer[ISO7816.OFFSET_LC];
        byte byteRead = (byte) (apdu.setIncomingAndReceive());
    
        if ((numBytes != 2) || (byteRead != 2)) {
            ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        }
    
        short chargeAmount = (short) ((short) (buffer[ISO7816.OFFSET_CDATA] << (short) 8) | (buffer[ISO7816.OFFSET_CDATA + 1]));
    
        if ((chargeAmount > MAX_BALANCE) || (chargeAmount < (short) 0)) {
            ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
        }
    
        if ((short) (balance + chargeAmount) > MAX_BALANCE) {
            ISOException.throwIt(SW_MAX_BALANCE_EXCEEDED);
        }
        JCSystem.beginTransaction();
        balance = (short) (balance - chargeAmount);
        JCSystem.commitTransaction();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are writing apps for Android and so far only use the simulator. What
I am writing an output module to visualize my data on another program. If
Writing a simple example from Odersky's book resulted in the following problem: // AbstractElement.scala
Writing a sound control applet with GUI that communicates with a device via USB.
Writing a function to generate and push some random data inside of the unknown
Writing a program in which I need to split strings from a struct linked
Writing an app with django, using the psycopg2 engine. It doesn't always seem to
Writing a rather simple command line tool in ruby I need to report meaningful
writing to a text file is working good...But my problem is text file is
I am running a simulation in C, and need to store 3 100x100 matrices

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.