首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ACR122u/Python3 3/智能卡库如何读取块

ACR122u/Python3 3/智能卡库如何读取块
EN

Stack Overflow用户
提问于 2019-12-05 15:02:51
回答 1查看 730关注 0票数 0

我试图通过使用智能卡python3库从MIFARE1K令牌读取块,但我没有得到数据。我用的是ACR122u-A9。

代码语言:javascript
复制
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区,不能读其他的部分。

EN

回答 1

Stack Overflow用户

发布于 2019-12-06 14:30:00

我找到了一种读取扇区/区块的方法,我不确定它是否正确,但它在A键上运行得很好。

代码语言:javascript
复制
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")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59197934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档