我试图通过使用智能卡python3库从MIFARE1K令牌读取块,但我没有得到数据。我用的是ACR122u-A9。
import smartcard
from smartcard.util import toHexString
COMMAND = [0xFF, 0xCA, 0x00, 0x00, 0x00]
READ_16_BINARY_BLOCKS = [0xFF,0xB0,0x00,0x04,0x10]
sprotocol = smartcard.scard.SCARD_PROTOCOL_T1
reader = smartcard.System.readers()
conn = reader[0].createConnection()
conn.connect()
result, sw1, sw2 = conn.transmit(COMMAND,protocol = sprotocol)
if (sw1, sw2) == (0x90, 0x0):
print("The operation completed successfully.")
#AUTHENTICATE = [0xFF, 0x88, 0x00, BLOCK_NUMBER, 0x60, 0x00]
AUTHENTICATE = [0xFF, 0x88, 0x00, 0x01, 0x60, 0x00] #Authenticate block 1
response = conn.transmit(AUTHENTICATE)
print(response)
if response[1] == 144:
print("Authenticated successfully")
value, sw1,sw2 = conn.transmit(READ_16_BINARY_BLOCKS) #read block 1
print(value,sw1,sw1)但产出总是:
output1:操作成功完成。
output2:([],144,0)
output3:成功认证
output4:[] 99 99
最后一个输出应该给我一个十六进制数据列表,但我没有得到任何东西,甚至试图读取块0x00,同样的事情。
更新--我能够读到第4~7块,我认为这是第1区,不能读其他的部分。
发布于 2019-12-06 14:30:00
我找到了一种读取扇区/区块的方法,我不确定它是否正确,但它在A键上运行得很好。
import smartcard
from smartcard.util import toHexString
import time
reader = smartcard.System.readers()
if not reader:
print("No readers")
else:
conn = reader[0].createConnection()
conn.connect()
#[0xFF, 0x82, 0x00, 0x00, 0x06,KEY(6 bytes)]
LOADKEY = [0xFF, 0x82, 0x00, 0x00, 0x06,255,255,255,255,255,255]
response = conn.transmit(LOADKEY)
if response[1] == 144:
print("Key A loaded successfully")
time.sleep(2)
#auth block
#[0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, BLOCK, KEY-TYPE, 0x00]
COMMAND = [0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x60, 0x00]
response = conn.transmit(COMMAND)
print(response)
time.sleep(2)
#[0xFF, 0xB0, 0x00, BLOCK-NUMBER, 0x10]
read = [0xFF, 0xB0, 0x00, 0x00, 0x10] #Read block 0
data, sw1, sw2 = conn.transmit(read)
print(toHexString(data))
else:
print("Wrong key A")https://stackoverflow.com/questions/59197934
复制相似问题