Smartcardio.PCSC Gemplus Javacard中的终端连接错误 [英] Smartcardio.Terminal connection error in PCSC Gemplus Javacard
本文介绍了Smartcardio.PCSC Gemplus Javacard中的终端连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Java Card编程非常陌生。在我的代码中使用javax.Smartcardio时,
尝试连接到Gemalto PCSC Java卡时出现错误。
I am extremely new to Java Card programming. While using javax.Smartcardio in my code, I am getting an error while trying to connect to Gemalto PCSC Java card.
import java.util.List;
import javax.smartcardio.*;
public class App
{
public static void main(String[] args) {
try {
// Display the list of terminals
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
// Use the first terminal
CardTerminal terminal = terminals.get(0);
if (terminal.isCardPresent()) {
System.out.println("Card present!");
}
// Connect with the card
Card card = terminal.connect("*");
System.out.println("card: " + card);
CardChannel channel = card.getBasicChannel();
// Send Select Applet command
byte[] aid = {(byte)0xA0, 0x00, 0x00, 0x00, 0x62, 0x03, 0x01, 0x0C, 0x06, 0x01};
ResponseAPDU answer = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x04, 0x00, aid));
System.out.println("answer: " + answer.toString());
// Send test command
answer = channel.transmit(new CommandAPDU(0x00, 0x00, 0x00, 0x00));
System.out.println("answer: " + answer.toString());
byte r[] = answer.getData();
for (int i=0; i<r.length; i++)
System.out.print((char)r[i]);
System.out.println();
// Disconnect the card
card.disconnect(false);
} catch(Exception e) {
System.out.println("Ouch: " + e.toString());
}
}
}
输出结果如下:
Terminals: [PC/SC terminal Gemplus USB Smart Card Reader 0]
Gemplus USB Smart Card Reader 0
Card present!
Ouch: javax.smartcardio.CardException: connect() failed
我无法找出我的卡的真正问题。来自供应商的VB API似乎运行良好。目前不允许发布图片。
I am not able to figure out the real issue with my card. The VB API that has come from vendor seems to be working fine. I am not allowed to post image at the moment.
根据API,
ATR: A2 13 10 91
APDU Send Data: 20 12 01 01 00
APDU Reply Data: A2 13 10 91 90 00
我们将不胜感激。
推荐答案
检查junit测试以获取更多示例
Check junit test for more example
例如,我执行以下操作并设法检测SMARTCART是否已连接。
For example I did as follows and manages to detect whether the SMARTCART is connected.
public class Prueba {
public static void main(String[] args) throws Exception
{
TerminalFactory context;
Security.addProvider(new Smartcardio());
context = TerminalFactory.getInstance("PC/SC", null, Smartcardio.PROVIDER_NAME);
// Display the list of terminals
List<CardTerminal> terminals_list = context.terminals().list();
if (terminals_list.isEmpty())
{
System.err.println("No existen dispositivos conectados...");
return;
}
// Use the first terminal
CardTerminal terminal = terminals_list.get(0);
if (terminal.isCardPresent())
{
System.out.println("La tarjeta electronica esta presente!: "+terminal.getName());
}
else
{
System.out.println("La tarjeta electronica NO esta presente");
}
}
}
}
这篇关于Smartcardio.PCSC Gemplus Javacard中的终端连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文