【PC / SC智能卡】javax.smartcardio.CardException: connect() failed 解决办法

2023-05-10 19:16:49 浏览数 (1)

如标题所述, 我在进行Windows 上的智能卡交互系统的研发。

此问题是出现在了连接过程中, 如下代码所示:

代码语言:javascript复制
CardTerminal card =c.connect("T=0");

解决办法:

代码语言:javascript复制
//将T=0协议换成* ,意思是说让系统自动寻找合适的协议
CardTerminal card =c.connect("*");

如果想了解原因所在, 那么继续往下翻。

具体错误信息如下:

代码语言:javascript复制
javax.smartcardio.CardException: connect() failed
	at sun.security.smartcardio.TerminalImpl.connect(Unknown Source)
	at com.gd.factory.utils.EseTools.connect(EseTools.java:160)
	at com.gd.factory.ui.MainJMiddleView.actionPerformed(MainJMiddleView.java:283)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: sun.security.smartcardio.PCSCException: SCARD_E_PROTO_MISMATCH
	at sun.security.smartcardio.PCSC.SCardConnect(Native Method)
	at sun.security.smartcardio.CardImpl.<init>(Unknown Source)

具体原因是在于这里:

Caused by: sun.security.smartcardio.PCSCException: SCARD_E_PROTO_MISMATCH

其实, “SCARD_E_PROTO_MISMATCH” 的意思是 表明该卡不支持您正在使用的协议,说到这里相信你就应该明白了,因为Java和Windows的本机智能卡API之间的接口可能不允许(或实现)强制执行特定协议,而且在SLE-4428卡上找到的数据表似乎没有提到卡支持的协议。

0 人点赞