How to store offline payment data in Java Card?

JavaCard Applet Development Related Questions and Answers.
herry
Posts: 15
Joined: Thu Jul 19, 2018 2:36 am
Points :208
Contact:

How to store offline payment data in Java Card?

Post by herry » Sun Feb 17, 2019 12:38 am

I am new to Java Card. I want to know how to store some offline data (such as a balance). Does it need to use a file structure(compliance to 7816 standard) to store data?

kuafu
Posts: 150
Joined: Thu Jun 25, 2015 2:09 am
Points :1613
Contact:

Re: How to store offline payment data in Java Card?

Post by kuafu » Sun Feb 17, 2019 7:15 am

define your own file struct to store data.
https://github.com/JavaCardOS/Java-Card ... ystem.java
viewtopic.php?f=34&t=24d
Defile your FileSystem that you need to store data!

Code: Select all

    private void processWriteBinary(APDU apdu) throws ISOException {
        if(state != STATE_INITIAL) {
            ISOException.throwIt(SW_INS_NOT_SUPPORTED);
        }
        byte[] buf = apdu.getBuffer();
        byte p1 = buf[OFFSET_P1];
        byte p2 = buf[OFFSET_P2];
        short offset = 0;
        short ef = -1;
        if((byte)(p1 & MASK_SFI) == MASK_SFI) {
            byte sfi = (byte)(p1 | ~MASK_SFI);
            if(sfi >= 0x1F) {
                ISOException.throwIt(SW_INCORRECT_P1P2);
            }
              ef = fileSystem.findCurrentSFI(sfi);
              if(ef == -1) {
                ISOException.throwIt(SW_FILE_NOT_FOUND);
              }
              ef = fileSystem.fileStructure[ef];
            offset = unsigned(p2);
        }else{
            ef = fileSystem.getCurrentIndex();
            if(fileSystem.getFile(ef) == null) {
                ISOException.throwIt(SW_COMMAND_NOT_ALLOWED);                
            }
            offset = Util.makeShort(p1, p2);
        }
        byte[] file = fileSystem.getFile(ef);
        short lc = unsigned(buf[OFFSET_LC]);
        if((short)(offset + lc) > file.length) {
            ISOException.throwIt(SW_WRONG_LENGTH);
        }
        apdu.setIncomingAndReceive();
        Util.arrayCopyNonAtomic(buf, OFFSET_CDATA, file, offset, lc);
    }
well

kuafu
Posts: 150
Joined: Thu Jun 25, 2015 2:09 am
Points :1613
Contact:

Re: How to store offline payment data in Java Card?

Post by kuafu » Sun Feb 17, 2019 7:52 am

http://javacardos.com/javacardforum/vie ... ?f=42&t=27 In this project store data with OathObj object.there is no suitable file struct to fit your need,youneed to define your file struct.
well

herry
Posts: 15
Joined: Thu Jul 19, 2018 2:36 am
Points :208
Contact:

Re: How to store offline payment data in Java Card?

Post by herry » Mon Feb 18, 2019 11:38 pm

Thank you very much for your reply

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 3 guests

JavaCard OS : Disclaimer