Python read text from NFC ACR122U

I successfully could read the UID of a NFC card, using the reader ACR122U and a simple badge bought on aliexpress.

The problem is that i can’t manage to read something else. I want to read the text that is written in the tag. I wrote the text with my smartphone.

I know that you can read the UID without any key.

And i know that you need two keys to access the data. I also know that the default keys are all 0x00…

This is the code that only reads UID and works fine:

from smartcard.System import readers
from smartcard.util import toHexString
import time

def read_card():
    r = readers()
    if len(r) == 0:
        print("Nessun lettore NFC trovato.")
        return None

    reader = r[0]
    connection = reader.createConnection()

    try:
        connection.connect()
        get_uid_command = [0xFF, 0xCA, 0x00, 0x00, 0x00]
        data, sw1, sw2 = connection.transmit(get_uid_command)

        if sw1 == 0x90 and sw2 == 0x00:
            return toHexString(data)
        else:
            return None
    except Exception as e:
        print(f"Errore durante la lettura della carta: {e}")
        return None

if __name__ == "__main__":
    while True:
        print("In attesa di una carta...")
        uid = None
        while not uid:
            uid = read_card()
            if not uid:
                time.sleep(0.3)

        print(f"UID della carta: {uid}")
        print("Rimuovi la carta e passa un'altra per continuare.")
        time.sleep(2) #Pausa dopo la lettura per impedire che venga riletta la stessa card.

i and this the code that i tried but that continuosly fail the auth, giving me 63 00 error instead of 90 00.

from smartcard.System import readers
from smartcard.util import toHexString
import time

#Keys
KEYA = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
KEYB = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]

SECTOR_NUMBER = 3  #Sector number
BLOCK_NUMBER = 12   #Block number

def authenticate_sector(connection, sector_number, key):
    auth_command = [0xFF, 0x88, 0x20, sector_number * 4, 0x60] + key
    _, sw1, sw2 = connection.transmit(auth_command)
    return sw1, sw2

def read_card():
    r = readers()
    if len(r) == 0:
        print("Nessun lettore NFC trovato.")
        return None

    reader = r[0]
    connection = reader.createConnection()

    try:
        connection.connect()

        #Attempt to authenticate with KEYA first
        sw1, sw2 = authenticate_sector(connection, SECTOR_NUMBER, KEYA)
        if sw1 != 0x90 or sw2 != 0x00:
            #If KEYA authentication fails, try KEYB
            sw1, sw2 = authenticate_sector(connection, SECTOR_NUMBER, KEYB)
            if sw1 != 0x90 or sw2 != 0x00:
                print(f"Autenticazione fallita: SW1={sw1:02X}, SW2={sw2:02X}")
                return None

        #Read data from the specified block
        read_command = [0xFF, 0xB0, BLOCK_NUMBER, 0x00, 0x10]  #Adjust the length as needed
        data, sw1, sw2 = connection.transmit(read_command)

        if sw1 == 0x90 and sw2 == 0x00:
            return bytes(data).decode('utf-8')  #Data is in UTF-8 format
        else:
            print(f"Lettura dei dati fallita: SW1={sw1:02X}, SW2={sw2:02X}")
            return None
    except Exception as e:
        print(f"Errore durante la lettura della carta: {e}")
        return None

if __name__ == "__main__":
    while True:
        print("In attesa di una carta...")
        data = None
        while not data:
            data = read_card()
            if not data:
                time.sleep(0.3)

        print(f"Dati della carta: {data}")
        print("Rimuovi la carta e passa un'altra per continuare.")
        time.sleep(2) #Pause after reading, just to not read again the same card.

I also tried various type of the auth commands, reading the documentation i found:

[! page documentation]

This is the pdf (in this case page 27): https://www.epsys.no/downloads/pdf/API_ACR128_v1.9.pdf

Does anybody know where i’m wrong? Thanks! Please don’t remove my question again.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật