6

I'm trying to learn about how does Java access smart cards, due to a project analysis. I wonder if there is any kind of virtual smart card which I could use to make some tests with Java?

By the way, I've read about Java Card, and looks like it is used to run Java in cards, not to smart card data access using Java, right?

The Student
  • 27,520
  • 68
  • 161
  • 264

5 Answers5

9

Look at this tutorial + example. And related. (I have used these examples and they work fine).

An important point is that you can't get anything out of the smart card. You can only send things to its processor. So whenever you get a PrivateKey object, you don't actually have the private key - this is only a proxy to the SmartCard processor, and calling methods on it, calls the processor.

I'm not aware of virtual smart cards, though.

An API of interest is javax.smartcardio

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • I "can't get anything out of the smart card" doesn't mean I can't get its public key, I hope – The Student May 12 '10 at 14:19
  • 1
    Ok, I found further about: http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/smartcardio/javax.smartcardio.htm – The Student May 12 '10 at 14:32
  • you can get the public key, yes – Bozho May 12 '10 at 14:33
  • You can get anything out of a smart card that the card application developer will let you get out of the card. It is considered a FIPS-140 security token so it is intended to be secure. – Shane Nov 25 '10 at 23:32
  • Hi Tom, had you at the end any working example? I tried sending commands to real card according http://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-4_5_basic_organizations.aspx#chap5_3 but nothing makes sense - I'm getting responses but all of them are some info about error. Ieg. do you have any example how to read user certificate with public key from card? – igor.beslic Sep 28 '11 at 14:05
2

There is a Java Card emulator bundled with the Java Card Development Kit. If you plan on using a real card at some stage, get version 2.2.1 or 2.2.2 as I would not expect any version 3 cards for a while. You will still need an applet to put on the card. A java card does nothing by itself. It isn't until you load a card applet that it will perform any useful function.

One problem with the emulator in the JCDK is that you cannot use javax.smartcardio to access the card and this is the prefered method at the moment for communicating with a card. The other popular alternative, OpenCard Framework, has not been actively maintained in some time.

Shane
  • 1,255
  • 14
  • 14
1

Javacard use Java only a subset of the Java development You'd better not use Java development environment Because there are some special effects is not support You can download the plugin or a dedicated development IDE, you can download it from here www.javacos.com related development environment.

1

You can get a virtual smartcard (and a virtual reader) here: http://sourceforge.net/projects/vsmartcard/

Fa11enAngel
  • 4,690
  • 2
  • 39
  • 38
0

If you need to emulate JavaCard try to use jCardSim: http://jcardsim.org. It also supports access via javax.smartcardio API and apdu-scripts.

MikhailDudarev
  • 461
  • 4
  • 8