如何从 HID omnikey 获取智能卡的 TAR
Posted
技术标签:
【中文标题】如何从 HID omnikey 获取智能卡的 TAR【英文标题】:How to get ATR of a smard card from HID omnilkey 【发布时间】:2014-12-31 07:19:05 【问题描述】:我想获取智能卡的 ATR。我正在使用 HID omnikey 5321。我正在关注此链接“http://pyscard.sourceforge.net/user-guide.html#requesting-any-card”
到目前为止我已经尝试过:
>>>from smartcard.CardType import AnyCardType
>>>from smartcard.CardRequest import CardRequest
>>>from smartcard.util import toHexString
>>>
>>> cardtype = AnyCardType()
>>> cardrequest = CardRequest( timeout=1, cardType=cardtype )
>>> cardservice = cardrequest.waitforcard()
>>>
>>>>>> cardservice.connection.connect()
我遇到了错误
cardservice.connection.connect()
类似的错误:
raise CardConnectionException('Unable to connect with ptotocol[pcscprotocol] + . '+ScardGetErrorMessage(hresult)
CardConnectionException: Unable to conenct the card with T0 or T1 . Card is not responding to reset.
【问题讨论】:
你的卡是非接触式的吗? 【参考方案1】:在python中,您可以使用pyscard库与智能卡进行交互,有一个示例可以帮助您在http://pyscard.sourceforge.net/pyscard-framework.html#framework-samples显示ATR
【讨论】:
在上面的链接中提到了javascript。怎么办呢 我想从python而不是从网页中获取它,并且所有卡都有ATR吗?为什么因为我在访问卡的 atr 时什么都没有,所以我得到了一个空列表【参考方案2】:因为您没有指定要连接的阅读器:
r=readers()
#r[Number of reader list].
cardservice.connection = r[0].createConnection()
cardservice.connection.connect()
一个简单的例子:
from __future__ import print_function
from smartcard.Exceptions import NoCardException
from smartcard.System import readers
from smartcard.util import toHexString
for reader in readers():
try:
connection = reader.createConnection()
connection.connect()
print(reader, toHexString(connection.getATR()))
except NoCardException:
print(reader, 'no card inserted')
import sys
if 'win32' == sys.platform:
print('press Enter to continue')
sys.stdin.read(1)
-另一个选择阅读器:
from __future__ import print_function
from smartcard.Exceptions import NoCardException
from smartcard.System import readers
from smartcard.util import toHexString
from smartcard.CardType import AnyCardType
from smartcard.CardRequest import CardRequest
cardtype = AnyCardType()
r=readers()
cardrequest = CardRequest( timeout=10, cardType=cardtype )
cardservice = cardrequest.waitforcard()
print('Available Readers:')
for i in range(len(readers())):
print('[',i+1,']',r[i])
if(len(readers()) < 1):
print("\nNO AVAILABLE READERS!\n")
else:
print("Select you Reader: (Ctrl+C to Exit)")
my_input = input()
selectReader = clamp(int(my_input)-1,0,len(readers()))
print('Selected: ',r[selectReader])
cardservice.connection = r[selectReader].createConnection()
cardservice.connection.connect()
try:
print('Card ATR:',toHexString(cardservice.connection.getATR()),file=f)
except:
print("Cant not Get ATR")
.
完整信息:
https://pyscard.sourceforge.io/pyscard-framework.html#framework-samples
https://github.com/LudovicRousseau/pyscard
https://pyscard.sourceforge.io/user-guide.html
【讨论】:
以上是关于如何从 HID omnikey 获取智能卡的 TAR的主要内容,如果未能解决你的问题,请参考以下文章
将 javax.smartcardio 用于 MIFARE Classic 和 Omnikey 5021 CL