Hi Jean-Pascal,

The code for writing a simple string on a smart card is indeed very simple.
What is more complex, is that you must prepare the card for it. You either
need a javacard with an appropriate applet on it, or an ISO7816-compatible
card with an appropriate file structure on it.

When your card is ready, you write your applciation either by using special
CardServices provided by the card manufacturer, or, to keep your app simple,
with the PassThruCardService included in OCF.

We here at the university are using STARCOS cards from Giesecke&Devrient
(http://www.gdm.de/starcos). For my experiments, I only use the
PassThruCardService.

Here is some sample code, which simply selects a file, just to show you how
to send a command to the card :

import opencard.core.service.SmartCard;
import opencard.core.service.CardRequest;
import opencard.opt.util.PassThruCardService;
import opencard.core.util.OpenCardPropertyLoadingException;
import opencard.core.service.CardServiceException;
import opencard.core.terminal.CardTerminalException;
import opencard.core.terminal.CommandAPDU;
import opencard.core.terminal.ResponseAPDU;

public class scard
{
        public static void main(String[] args)
        {
                System.out.println("Starting OpenCard...");
                try
                {
                        SmartCard.start();
                        System.out.println("Started! Waiting for card...");
                        CardRequest cr=new
CardRequest(CardRequest.ANYCARD,null,PassThruCardService.class);
                        SmartCard sc=SmartCard.waitForCard(cr);
                        PassThruCardService
serv=(PassThruCardService)sc.getCardService(PassThruCardService.class,true);
                        System.out.println("Card inserted and pass-through service
instatiated.");

                        //You have your card and service ready
here--------------------------------

                        byte[] arr=new byte[7];
                        arr[0]=(byte)0x00; //This is a SELECT APDU
                        arr[1]=(byte)0xa4;
                        arr[2]=(byte)0x02;
                        arr[3]=(byte)0x0c;
                        arr[4]=(byte)0x02;
                        arr[5]=(byte)0x10;
                        arr[6]=(byte)0x20;
                        CommandAPDU com=new CommandAPDU(arr);
                        System.out.println("Sending APDU... (Select file)");
                        ResponseAPDU resp=serv.sendCommandAPDU(com);
                        System.out.println("Response: "+resp.toString());
                        //---- Other commands may follow now 
----------------------------
                        SmartCard.shutdown();
                        System.out.println("OCF shut down.");
                }
                catch(Exception e)
                {
                        System.out.println("Exception: "+e.getMessage());
                        return;
                }
        }
}

Hope this helps all beginners.

Later,
Michael Pramateftakis

-------------------------------------------
Dipl.-Ing. M. Pramateftakis
Institute for Data Processing
Technical University of Munich, Germany
Tel: (+49 89) 289-23622
email: [EMAIL PROTECTED]
-------------------------------------------


> -----Urspr�ngliche Nachricht-----
> Von: Jean-Pascal RISS [mailto:[EMAIL PROTECTED]]
> Gesendet: Donnerstag, 27. April 2000 10:08
> An: [EMAIL PROTECTED]
> Betreff: [OCF] read and write a simple string
>
>
> hello all,
>
> I have a gemplus 410 card reader.
> My goal is to read and write a simple string
> on a smart card.
> Which smartcard must i use?
> Do i need Cardservice, if yes, where can i find this?
> Do you have samples code for this?
>
> thanks,
>
>
>
> ---
> > Visit the OpenCard web site at http://www.opencard.org/ for more
> > information on OpenCard---binaries, source code, documents.
> > This list is being archived at http://www.opencard.org/archive/opencard/
>
> ! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
> ! to
> !                           [EMAIL PROTECTED]
> ! containing the word
> !                           unsubscribe
> ! in the body.
>
>



---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/

! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
!                           [EMAIL PROTECTED]
! containing the word
!                           unsubscribe 
! in the body.

Reply via email to