Javax.smartcardio problems...

HI, i am trying to develop a simple applet in java, which should read data from a smartcard...
But when i want to read the terminals:
CardTerminal terminal = (CardTerminal)factory.terminals().get(0);
the full method:
CardTerminal terminal = (CardTerminal)factory.terminals().get(0);
try {
               terminal.waitForCardPresent(15000);
     if(terminal.isCardPresent())
     System.out.println("Card Inserted!!");
     else
     System.out.println("TimeOut reached!!");
          } catch (CardException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
an error occoures because factory.terminals() is empty.
Do you have any idea how to get the terminal list?
greets

Hi!
Are you running Windows or Linux? If you're using Windows, you shouldn't have any problem. But if it's Linux, you should download pcsc-lite and ccid. Try to google for these packages.
See ya! ;)

Similar Messages

  • Javax.smartcardio problem on linux SuSE

    HI, i am trying to develop a simple applet in java, which should read data from a smartcard...
    But when i want to read the terminals:
    CardTerminal terminal = (CardTerminal)factory.terminals().get(0);
    the full method:
    CardTerminal terminal = (CardTerminal)factory.terminals().get(0);
    try {
    terminal.waitForCardPresent(15000);
    if(terminal.isCardPresent())
    System.out.println("Card Inserted!!");
    else
    System.out.println("TimeOut reached!!");
    } catch (CardException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    an error occoures because factory.terminals() is empty.
    Do you have any idea how to get the terminal list?
    greets
    Robson Previato

    ps aux|grep pcscd
    ?

  • Problem with APDUCommand in javax.smartcardio

    Hi,
    There seem to be a bug (from my point of view) with the javax.smartcardio when i attempt to send a command over to the card.
    There a code frag
    factory = TerminalFactory.getDefault();
            try {
                terminals = factory.terminals().list();
                System.out.println("Terminals: " + terminals);
                terminal = terminals.get(1);
                System.out.println("Card Present: " + terminal.isCardPresent());
                Card card = terminal.connect("*");
                channel = card.getBasicChannel();
                ResponseAPDU resp = channel.transmit(new CommandAPDU(selectcom));
                System.out.println("Select Resp: " + getHexString(resp.getBytes()));
                CommandAPDU com = new CommandAPDU((byte)0x43, (byte)0x52, (byte)0x00, (byte)0x00, 0);
                System.out.println("CommandAPDU: " + getHexString(com.getBytes()));
                resp = channel.transmit(com);
                System.out.println("Result: " + getHexString(resp.getBytes()));
                card.disconnect(false);
            } catch (CardException e) {
                e.printStackTrace();
            }There the result:
    Terminals: [PC/SC terminal OMNIKEY CardMan 5x21 0, PC/SC terminal OMNIKEY CardMan 5x21-CL 0]
    Card Present: true
    Select Resp: 90 00
    CommandAPDU: 43 52 00 00
    Result: 6E 00
    BUILD SUCCESSFUL (total time: 1 second)
    And there the result i tried with another tool (GPShell)
    select -AID 53504545454659503101
    --> 00A404000A53504545454659503101
    <-- 9000
    send_apdu -sc 0 -APDU 43520000
    Send APDU: 43 52 00 00
    --> 43520000
    <-- 9000
    Recv APDU: 90 00
    card_disconnect
    release_context
    Anyone have encounter the same problem?

    Refering to this code:
    factory = TerminalFactory.getDefault();
            try {
                terminals = factory.terminals().list();
                System.out.println("Terminals: " + terminals);
                terminal = terminals.get(1);
                System.out.println("Card Present: " + terminal.isCardPresent());
                Card card = terminal.connect("*");
                channel = card.getBasicChannel();
                ResponseAPDU resp = channel.transmit(new CommandAPDU(selectcom));
                System.out.println("Select Resp: " + getHexString(resp.getBytes()));
                CommandAPDU com = new CommandAPDU((byte)0x43, (byte)0x52, (byte)0x00, (byte)0x00, 0);
                System.out.println("CommandAPDU: " + getHexString(com.getBytes()));
                resp = channel.transmit(com);
                System.out.println("Result: " + getHexString(resp.getBytes()));
                card.disconnect(false);
            } catch (CardException e) {
                e.printStackTrace();
            }ResponseAPDU resp = channel.transmit(new CommandAPDU(selectcom));
    I already selected the applet here.
    With this command here
    static byte[] selectcom = new byte[] {(byte)0x00, (byte)0xA4, (byte)0x04, (byte)0x00, (byte)0x0A, (byte)0x53, (byte)0x50, (byte)0x45, (byte)0x45, (byte)0x45, (byte)0x46, (byte)0x59, (byte)0x50, (byte)0x31, (byte)0x01};
    So selecting the applet is done. And it return a 90 00. Then i start to send applet specific command.
    =)

  • Help me - I have a problem of using the javax.smartcardio

    Hi everybody!!!
    I'm creating an application to communicate with javacard.
    I searched on internet and know about javax.smartcardio.
    But I can not use it, even it's inside the default library of Java 6.
    I already import the javax.smartcardio.*; to my java file.
    But it can not find the class inside this package.
    Can somebody help me? Thanks a lot.

    Hi everybody.
    I got the advice from Mr. Safarmer on this forum.
    So:
    If you're using Eclipse to develop the application.
    You have to set the JRE Library to Alternate JRE.
    Below is the instruction for dummies like me ^^:
    Go to Build Path > Configure Buil Path of your project
    In Libraries tab, Edit the JRE System Library
    Instead of choosing the Execution Environment, we choose Alternate JRE (usually jre6)--> This is my case. And i did it.

  • Java 6: javax.smartcardio - can't get CPLC

    Hello! I have a problem - can't get CPLC with classes from javax.smartcardio (get SW=6a88), but I easily get it with com.sun.javacard.apduio classes from Java Card Kit 2.2.2.
    Here the test code for javax.smartcardio :
    import java.util.List;
    import javax.smartcardio.*;
    public class TestSmartCardJSE60
    public static void main(String[] args)
      try
       TerminalFactory tf = TerminalFactory.getInstance("PC/SC", null);
       CardTerminals cts = tf.terminals();
       List<CardTerminal> avaiableTerminals = cts.list();
       CardTerminal ct = avaiableTerminals.get(0);
       Card card = ct.connect("*");
       try
        CardChannel channel = card.getBasicChannel();
        CommandAPDU capdu = new CommandAPDU(0x80, 0xCA, 0x9F, 0x7F);
        ResponseAPDU res = channel.transmit(capdu);
        System.out.printf("%s%n", res);
       finally
        card.disconnect(true);
      catch(Exception e)
       e.printStackTrace();
    }And here the same for com.sun.javacard.apduio
    import com.sun.javacard.apduio.*;
    public class TestSmartCardJCK222
    public static void main(String[] args)
      try
       CadClientInterface cad = CadDevice.getPCSCClientInstance(0);
       cad.powerUp();
       try
        Apdu capdu = new Apdu();
        capdu.command[Apdu.CLA] = (byte) 0x80;
        capdu.command[Apdu.INS] = (byte) 0xCA;
        capdu.command[Apdu.P1] = (byte) 0x9F;
        capdu.command[Apdu.P2] = 0x7F;
        cad.exchangeApdu(capdu);
        System.out.printf("%s%n", capdu);
        capdu.setLe(0x2D);
        cad.exchangeApdu(capdu);
        System.out.printf("%s%n", capdu);
       finally
        cad.powerDown(true);
      catch(Exception e)
       e.printStackTrace();
    }I run both tests under WindowsXP SP3 with ORGA ECO5000 Usb and JCOP21 smart card.
    What is my problem? Actualy I want to use javax.smartcardio for my application, because classes from that package more useful than com.sun.javacard.apduio;
    Any ideas?

    You're missing the Le byte, since you're expecting data back. Try it.

  • How to get a handle which is used in c dll from  javax.smartcardio.card

    good afternoon
    i am using javax.smartcardio.card to operate a sim-card reader .
    but i have a dll which is call sim-card reader by handle.
    how can i get a handle from a javax.smartcardio.card object to pass to the dll
    next is the code .
    c dll prototype declaration
    char DoFormat([in] unsigned long P1�C[in] char * P2�C[in] bool P3,[in][out] char *P4)P1 is a handle
    java code:
    private boolean checkCardReader(boolean isopen)
    boolean r=false;
    try {
    javax.smartcardio.card card;
    TerminalFactory factory = TerminalFactory.getDefault();
    List terminalList = factory.terminals().list();
    terminal = (CardTerminal) terminalList.get(0);
    // establish a connection with the card
    card = terminal.connect("T=0");
    channel = card.getBasicChannel();
    //how can i get a handle which can be used by windows dll .
    }catch (Exception ex)
    System.out.println("Exception : " + ex);
    return r;
    *****************************************************************

    Presumably you are calling a C library method that returns a handle.
    Normally a handle will be a integer type value.
    With such a value you can cast it into a java integer type and then cast it back in different JNI code by passing it to those routines.
    A java long is as big as you can get and will hold most every normal type handle item. You should however verify sizes.

  • Help need in javax.smartcardio.exception

    getting error
    javax.smartcardio.CardException: sun.security.smartcardio.PCSCException: Unknown error 0xc000002b
    at sun.security.smartcardio.ChannelImpl.doTransmit(ChannelImpl.java:202)
    at sun.security.smartcardio.ChannelImpl.transmit(ChannelImpl.java:73)
    while setting pin limit in the card.
    Please help what is the cause of getting this error.
    thanks in advance

    First you should check that the library has the checkbox 'Deploy by default' is checked for your library.
    The you open the project properties of the view controller project, select Deployments, edit the deployment descriptor. Select the Node 'File Groups'->'WEB-INF/lib'->'Contributors'. this should give you a list of libraries your project uses. Check if your library has the checkbox checked (is selected fro deployment). If it's not checked, set it.
    This should include the library.
    Timo

  • How to get free memory size of a card with javax.smartcardio

    Hi,
    How can I find how much memory of a card is free with javax.smartcardio?
    Please your advice.
    Thank in advance.

    gizmo wrote:
    I wanted to read the free memory size with a card reader and javax.smartcardio.
    Is it possible to send a APDU Command to select the root 3F00 and read the properties?There is no built-in smartcardio funationality to do this. What you can do is send an APDU and get the memory by calling the code mentioned already.

  • Javax.smartcardio package not found in Java source file

    I downloaded the latest JDK from developer.apple.com, but now I cannot find the javax.smartcardio package in the source package (src.jar) that came with it. I unpacked the JAR file, but simply can't find the stated package. Can you help me out?

    I can confirm the issue here (Mountain Lion, 10.8.5). A very simple program (attached below) that just enumerates terminals and checks if a card is present will crash:
    If Apple JDK6 is used in 64-bit mode (without supplying the -d32 argument)
    If Oracle JDK7 is used (can not switch to 64-bit, uses)
    It will work if:
    If Apple JDK6 is forced into 32-bit mode using -d32
    If Oracle JDK7 version of libj2pcsc.dylib is replaced with a patched version
    javax.smartcardio on Mac OS X is in a truly sad state. :-(
    Can anyone suggest alternatives for Smartcard communication on Mac OS X fat clients?
    package com.example.smartcardio;
    import javax.smartcardio.CardTerminal;
    import javax.smartcardio.CardTerminals;
    import javax.smartcardio.TerminalFactory;
    public class TestWaitForChanges {
              public static void main(String[] args) throws Exception {
                        CardTerminals terminals = TerminalFactory.getDefault().terminals();
                        while (true) {
                                  for (CardTerminal terminal : terminals.list()) {
                                            System.out.println("Checking terminal: " + terminal.getName());
                                            System.out.println("Card present: " + (terminal.isCardPresent() ? "YES" : "NO"));
                                  System.out.println("Waiting for changes...");
                                  terminals.waitForChange();

  • PC/SC with JNI vs. javax.smartcardio

    Hi,
    for programming card terminals (USB tag readers) the PC/SC was used with JNI. Since the Java Smartcard I/O API (javax.smartcardio, JSR 268) was introduces in 1.6 it makes the JNI obsolete right?
    So there is no need for jpcsc and similar?
    Thanks
    STeN
    Edited by: stenlik on Jun 8, 2011 8:39 PM

    smartcardio uses JNI to access the PC/SC layer. It is built into the JDK so you do not have to distribute the JAR/DLL files any more as they are already delivered. jpcsc still has it's place but as you mentioned it is not required any more (unless your JDK does not have smartcardio).
    Cheers,
    Shane

  • Usage of javax.smartcardio package in eclipse

    Hi ,
    how to use this package (javax.smartcardio) in eclipse env

    Hi,
    Can you give more details about your issues? Have you searched the forum/web for examples?
    Cheers,
    Shane

  • Javax.print problems on applet - bug on mac os implementation?

    Dear All,
    I am working on an applet and application that include a print function and I get a weird behaviour on MacOS in applet mode (both with Safari and Firefox - Mac OS X Versione 10.4.9 (Build 8P135) ). In contrast, things work fine on Windows XP (both Explorer 7 and Firefox with Java Plug-in 1.6.0_01) and even in MacOS when using the application.
    The problems are:
    - the print dialogue goes on and off a few times before letting the user interact with it
    - the page format in the dialogue is set to A5 (instead of the printer's default)
    - there is a small empty window appearing together with the dialogue and not disappearing even after the applet is closed
    Is this a known problem? If so, are there work-arounds?
    (I had no luck on Google about this)
    To reproduce the problem I created a stripped down version of the applet, in 2 files, I report it at the bottom of this message. I am using a modified version the PrintUtilities class from http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html
    Am I doing something wrong? Or shall I consider submitting a bug report?
    Any suggestion is welcome! Please let me know if I should provide more detailed information.
    Thank you in advance,
    Enrico
    PrintMe.java
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    public class PrintMe extends JApplet implements MouseListener{
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         public PrintMe() {
              super();
         private class MyComponent extends JPanel{
              private static final long serialVersionUID = 1L;
              public void paintComponent(Graphics g) {
                   super.paintComponent(g);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setColor(Color.black);
                  g2.drawString( "Test text", 0, g2.getFontMetrics().getHeight() );
         public void init() {
              MyComponent aComponent = new MyComponent();
              jContentPane = new JPanel();
              jContentPane.setLayout(new BorderLayout());
              jContentPane.add(aComponent);
              this.setContentPane(jContentPane);
              this.addMouseListener(this);
         public void print(){
              try{
                   PrintUtilities.printComponent(this);
              }catch (Exception e) {
                   e.printStackTrace();
         public void mouseClicked(MouseEvent e) {
              print();
         public void mouseEntered(MouseEvent e) {
              // not used
         public void mouseExited(MouseEvent e) {
              // not used
         public void mousePressed(MouseEvent e) {
              // not used
         public void mouseReleased(MouseEvent e) {
              // not used
    PrintUtilities.java
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.swing.RepaintManager;
    import javax.swing.RootPaneContainer;
    /** A simple utility class that lets you very simply print
    *  an arbitrary component. Just pass the component to the
    *  PrintUtilities.printComponent. The component you want to
    *  print doesn't need a print method and doesn't have to
    *  implement any interface or do anything special at all.
    *  If you are going to be printing many times, it is marginally more
    *  efficient to first do the following:
    *    PrintUtilities printHelper = new PrintUtilities(theComponent);
    *  then later do printHelper.print(). But this is a very tiny
    *  difference, so in most cases just do the simpler
    *  PrintUtilities.printComponent(componentToBePrinted).
    *  7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
    *  May be freely used or adapted.
    public class PrintUtilities implements Printable {
         private Component componentToBePrinted;
         public static void printComponent(Component c) {
              new PrintUtilities(c).print();
         public PrintUtilities(Component componentToBePrinted) {
              this.componentToBePrinted = componentToBePrinted;
         public void print() {
              try{
                   PrinterJob printJob = PrinterJob.getPrinterJob();
                   printJob.setPrintable(this);
                   PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
                   if( printJob.printDialog(attributes) ){
                        try {
                             printJob.setJobName("MyName");
                             printJob.print(attributes);
                        } catch(PrinterException pe) {
                             System.err.println("Error printing: " + pe);
                             pe.printStackTrace();
              }catch (Exception e) {
                   e.printStackTrace();
         public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
              if (pageIndex > 0) {
                   return(NO_SUCH_PAGE);
              } else {
                   RootPaneContainer rpc = (RootPaneContainer)(this.componentToBePrinted);
                   rpc.getRootPane().getGlassPane().setVisible( false );
                   Graphics2D g2d = (Graphics2D)g;
                   double sy = pageFormat.getImageableHeight() / componentToBePrinted.getHeight();
                   double sx = pageFormat.getImageableWidth() / componentToBePrinted.getWidth();
                   if( sx > sy ){
                        sx = sy;
                   }else{
                        sy = sx;
                   g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
                   g2d.scale(sx, sy);
                   disableDoubleBuffering(componentToBePrinted);
                   componentToBePrinted.paint(g2d);
                   enableDoubleBuffering(componentToBePrinted);
                   return(PAGE_EXISTS);
         /** The speed and quality of printing suffers dramatically if
          *  any of the containers have double buffering turned on.
          *  So this turns if off globally.
          *  @see enableDoubleBuffering
         public static void disableDoubleBuffering(Component c) {
              RepaintManager currentManager = RepaintManager.currentManager(c);
              currentManager.setDoubleBufferingEnabled(false);
         /** Re-enables double buffering globally. */
         public static void enableDoubleBuffering(Component c) {
              RepaintManager currentManager = RepaintManager.currentManager(c);
              currentManager.setDoubleBufferingEnabled(true);
    }

    Trying to answer to myself..
    Is it possible that the problems are due to me mixing java.awt.print and javax.swing.print ?

  • Javax.mail problem...can any1 help

    Hi all;
    me am using javamail version 1.3 to send simple text mail using smtp server...during compilation, no error arises but while running following exception arises;
    Sending failed; nested exception is: javax.mail.SendFailedException: Invalid Addresses; nested exception is: javax.mail.SendFailedException: 550 5.7.1 ... Relaying denied ; nested exception is: javax.mail.SendFailedException: 550 5.7.1 ... Relaying denied ; nested exception is: javax.mail.SendFailedException: 550 5.7.1 ... Relaying denied
    wat should i do...where does the problem lie...
    would b waiting desperately for immediate replies.
    Regards

    while executing the above mentioned code...following errors come out...
    javax.mail.SendFailedException: Sending failed;
    nested exception is:
         javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
         javax.mail.SendFailedException: 550 5.7.1 <[email protected]>... Relaying denied
    nested exception is:
         javax.mail.SendFailedException: 550 5.7.1 <[email protected]>... Relaying denied
    nested exception is:
         javax.mail.SendFailedException: 550 5.7.1 <[email protected]>... Relaying denied
         at javax.mail.Transport.send0(Transport.java:218)
         at javax.mail.Transport.send(Transport.java:80)
         at __27eayyaz._msgsend__jsp._jspService(/~ayyaz/msgsend.jsp:25)
         at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
         at com.caucho.jsp.Page.subservice(Page.java:485)
         at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:181)
         at com.caucho.server.http.Invocation.service(Invocation.java:291)
         at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:341)
         at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:268)
         at com.caucho.server.TcpConnection.run(TcpConnection.java:136)
         at java.lang.Thread.run(Thread.java:544)

  • Importing javax.ejb problems

    Hi,
    I have started learning EJB using netbeans 6.5 running on a mac os X 10.5.6. When i am trying to import javax.ejb and error stating that package javax.ejb does not exist.
    From a search on the net i have learned that on windows os it is a problem of class paths. I don't know how to solve this problem on mac.
    Thanks
    Ray

    Here is what I have done recently:
    I tried it in Eclipse, which also isn't able to find javax.ejb and java.ejb
    What is going wrong? It seems like j2ee.jar doesn't provide these libraries.
    Thank you.

  • Javax comm problems

    Hi,
    I am trying to communicate with the communication ports using javax comm API through an applet.
    I am using Java 1.3.1.
    It gives me the exception:
    java.lang.ClassNotFoundException:javax.comm.commPortIdentifier
    I run the same program not using the applet , it runs fine.(i.e.recognises the ports etc)
    i tried to using a signed applet for the communication and still the exception is raised.
    All the files like comm.jar and properties file and also windriver are located in the reqd locations.else my program would not have run without using the applet.
    Can someone suggest what could be causing this problem
    Thanks
    Sai

    I am having the same problems with this javax.comm package. I am using Java 1.3.1_01 under WIN2K. I checked the hardware profile, and it listed my serial ports. I also have a palmpilot which communicates with this serial port, and it works fine as well.
    I tryed installing it two different ways:
    1.)
    installed it as if I was using jdk1.1.x
    putting the comm.jar package in the <jdkroot>/lib dir
    putting the properties file in the <jdkroot>/lib dir
    putting the dll in the <jdkroot>/bin dir
    adding <jdkroot>/lib/comm.jar to the classpath.
    While this did not give me a runtime error, it would not recognize any of my serial ports.
    2.)
    installed it according to the jdk1.2 documentation
    comm.jar -> <jdkroot>/jre/lib/ext/ dir
    properties -> <jdkroot>/jre/lib
    dll -> <jdkroot>/jre/bin
    not altering the path
    This gave me the following runtime error:
    java.lang.NoClassDefFoundError: javax/comm/CommPortIdentifier
         at VirtualGPSConsoleApp.main(VirtualGPSConsoleApp.java:27)
    Exception in thread "main"
    Process VirtualGPSConsoleApp exited abnormally with code 1
    Please let me know if you make any headway.
    Thank you,
    [email protected]

Maybe you are looking for

  • Airport Extreme $1.99 upgrade.....where is it?......what is it for?

    I saw an article about Apple releasing an upgrade to the Airport Extreme. Something to do with making it so Core 2 Duo Macs can utilize their built-in "N" type networking for faster speeds. 1) Which Airport Extremes will be able to use these download

  • Error on apps

    Whenever I try to send requests on games connected to Facebook, it comes back with "an error occurred please try again later". I've tried later, turned the iPad off completely and then back on, removed and reinstalled the apps and even went as far as

  • Adding users programmatically

    How can I add users/groups via the Weblogic API? All I can find in the documenattion is interfaces, but no implementation classes. How can I instantiate the classes? Thanks, Andrew

  • Score window in page mode shows only part of the composition

    I have an on going issue in Logic X: The score in page mode mostly refuses to show more than a couple of pages. There does not seem to be a logical reason for this. Deleting the score window and replacing it by another one shows the same issue, but o

  • No audio after downloading Mac OS X 10.6 Snow Leopard - any suggestions??

    I bought the disk with Mac OS X 10.6 Snow Leopard directly from Apple. After installation, my audio no longer works. The Macbook still makes a sound when booting up, so the speakers still work, but I cannot get any audio to work now. Help!!!