PYTHON apdu命令
from PySmartCard.CpuCard import PcscReader
A实例化读卡器:pcsc = PcscReader()
B获取所有的读卡器列表:readerName = pcsc.get_pcsc_readerlist()
readerNameList = readerName.split(';')
for i in range(len(readerNameList)-1):
print("{} {} :{}".format('reader',i,readerNameList[i]))
C useReaderName = "SCM Microsystems Inc. SDI010 Contactless Reader 0"
useReaderName = "SCM Microsystems Inc. SDI010 Smart Card Reader 0"
useReaderName="ACS ACR122 0"
ATR = pcsc.connect_device(useReaderName)
print(ATR)
if ATR:
print("ConnectDevice Success...")
print("ATR: ", ATR)
bz=1
else:
print("ConnectDevice Failed!")
'''上电'''
print('*'*40)
#通信界面类型: 1-contact reader 2-contactless reader #1有线 2无线
readerType = 2
if 'Contactless'.lower() in useReaderName.lower():
readerType = 2
if 0== pcsc.power_on(readerType):
bz=2
print("Device PowerOn Success...")
else:
print("Device PowerOn Failed!")
D加载密码(FFFFFFFF):
apdu1='FF82 0000 06FF FFFF FFFF FF'
recv_list = []
sendApduCommand(pcsc,apdu1, recv_list, readerType)
if recv_list[1] !="9000":
print("Send Apdu Failed!")
E针对特定扇区06区进行密码认证
apduxx='FF86 0000 0501 003C 6000'
apduyx='FF86 0000 0501 003C 6100'
#FF86 0000 0501 0000 6000认证keya 00区 FF86 0000 0501 0000 6100 认证keyb 00区
#FF86 0000 0501 0010 6000认证keya 01区 FF86 0000 0501 0010 6100 认证keyb 01区
#FF86 0000 0501 0014 6000认证keya 02区 FF86 0000 0501 0014 6100 认证keyb 02区
#FF86 0000 0501 001E 6000认证keya 03区 FF86 0000 0501 001E 6100 认证keyb 03区
#FF86 0000 0501 0028 6000认证keya 04区 FF86 0000 0501 0028 6100 认证keyb 04区
#FF86 0000 0501 0032 6000认证keya 05区 FF86 0000 0501 0032 6100 认证keyb 05区
#FF86 0000 0501 003C 6000认证keya 06区 FF86 0000 0501 003C 6100 认证keyb 06区
recv_list = []
sendApduCommand(pcsc,apduxx, recv_list, readerType)
if recv_list[1]=="9000":
printf("密码正确")#第D步加载的密码FFFFFFFF正确