[ACR122u / Python3 / smartcard lib如何读取块

问题描述 投票:0回答:1

我正在尝试通过使用智能卡python3 lib从Mifare 1K令牌中读取块,但是我没有获取数据。我正在使用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)

但是输出始终是:

输出1:操作成功完成。

输出2:([[],144,0)

输出3:已成功验证

输出4:[] 99 99

最后一个输出应该给我一个十六进制数据列表,但是我什么也没得到,甚至试图读取块0x00,也是一样。

更新-我能够读取块4〜7,我认为这是扇区1,无法读取其他扇区。

python-3.x smartcard rfid mifare
1个回答
0
投票

[我找到了一种读取扇区/块的方法,我不确定这是否正确,但是使用键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")
© www.soinside.com 2019 - 2024. All rights reserved.