DzikiMarian
DzikiMarian

Reputation: 423

How to store data on javacard?

I'm experimenting with applet for JavaCard - it's very simple SCWS serverlet(basically template from Gemalto Dev Suite). I want it to store some data on card - how to do it? I found only some theoretical materials about linear and cyclical files.

//EDIT

I managed to find something like this:

private byte createfile()
    {
        try{
            AdminFileView uiccAdminFileView = AdminFileViewBuilder.getTheUICCAdminFileView(JCSystem.CLEAR_ON_RESET);
            if(uiccAdminFileView == null){
                return 'a';
            }
            uiccAdminFileView.select((short)0x7F60);
            EditHandler editHandler = (EditHandler) HandlerBuilder.buildTLVHandler(HandlerBuilder.EDIT_HANDLER,
                    (short) 50);
            editHandler.clear();
            editHandler.appendArray(CreateEF, (short) 0,(short) CreateEF.length);
            uiccAdminFileView.createFile(editHandler);
            data[0] = (byte) 0x12;
            data[1] = (byte) 0x34;
            data[2] = (byte) 0x56;
            uiccAdminFileView.select((short)0xEE00);
            uiccAdminFileView.updateBinary((short) 0, data, (short)0, (short)3);
        } catch(UICCException e){

            return (byte)e.getReason();
        }
        return 'b';
    }

But at this point it returns "a" every time - as far as I know it has something to do with access rights for applet.

Upvotes: 0

Views: 2996

Answers (3)

dim
dim

Reputation: 1717

It seems that your issue is answered here: http://developer.gemalto.com/nc/forums.html?view=single_thread&cat_uid=3&conf_uid=2&thread_uid=154

Upvotes: 0

Maarten Bodewes
Maarten Bodewes

Reputation: 94038

Once there was an ISO 7816-4 file based API in Java Card, but that has been sunk a long long time ago. Now you just have to program it yourself. You need at least the ISO 7816-4 (2005) standard handy to make anything remotely compatible with file based cards.

The real "fun" starts when you have to send file data from an offset of over 32K over a secure messaging channel while keeping an eye on file selection and access rights. For anybody reading the answer to this old question: good luck - and know it can be done.

Upvotes: 1

LeleDumbo
LeleDumbo

Reputation: 9340

For a "real" smart card, you create/edit/delete data either via something standard called APDU command. For this to work, there must be an OS installed on the card capable of handling the APDU to create/update/read files, etc. If the card is totally virgin (i.e. it has really nothing inside), you have to use the card's API or read the spec and do everything yourself (very likely you'll deal with assembly). I don't know what your card is so I can't give specific instructions, read your manual.

Upvotes: 0

Related Questions