包 javax.smartcardio


javax.smartcardio
Java™ 智能卡 I/O API。本规范描述了 JSR 268 定义的 Java 智能卡 I/O API。它定义了一个 Java API,用于使用 ISO/IEC 7816-4 APDU 与智能卡进行通信。因此,它允许 Java 应用程序与智能卡上运行的应用程序进行交互,在卡上存储和检索数据等。

API 由包 javax.smartcardio 中的类定义。它们可以分类如下:

描述相应智能卡结构的类
ATR , CommandAPDU , ResponseAPDU
获取实现的工厂
TerminalFactory
卡和终端功能的主要类
CardTerminals , CardTerminal , Card , CardChannel
支持权限和异常类
CardPermission , CardException , CardNotPresentException
服务提供者接口,应用程序不直接访问
TerminalFactorySpi

API范例

使用 API 的一个简单示例是:
   // show the list of available terminals
   TerminalFactory factory = TerminalFactory.getDefault();
   List<CardTerminal> terminals = factory.terminals().list();
   System.out.println("Terminals: " + terminals);
   // get the first terminal
   CardTerminal terminal = terminals.get(0);
   // establish a connection with the card
   Card card = terminal.connect("T=0");
   System.out.println("card: " + card);
   CardChannel channel = card.getBasicChannel();
   ResponseAPDU r = channel.transmit(new CommandAPDU(c1));
   System.out.println("response: " + toString(r.getBytes()));
   // disconnect
   card.disconnect(false);
 
自从:
1.6