Page 1 of 1

How to store offline payment data in Java Card?

Posted: Sun Feb 17, 2019 12:38 am
by herry
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?

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

Posted: Sun Feb 17, 2019 7:15 am
by kuafu
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);
    }

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

Posted: Sun Feb 17, 2019 7:52 am
by kuafu
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.

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

Posted: Mon Feb 18, 2019 11:38 pm
by herry
Thank you very much for your reply