HID iClass DL智能卡号解析求助:Omnikey 5022读取值无法匹配正确结果
解决HID iClass DL卡Weigand 26位编码解析错误问题
问题背景
- 设备:HID Omnikey 5022读卡器
- 卡片:HID iClass DL(读卡器识别为iClass 2ks,带Weigand 26位编码)
- 已知正确参数:设施码147,卡号4511
- 读取到的卡片数据:
- ATR:
3B8F8001804F0CA0000003060A0018000000007A - UID:
7BA49412FEFF12E0
- ATR:
- 尝试通用ATR解析步骤后得到错误结果:卡号128、设施码131,与实际值不符
原因分析
通用ATR解析方法仅适用于HID Prox等基础感应卡,iClass卡的Weigand编码并不存储在ATR中。ATR只是卡片的传输协议应答信息,不包含用户业务数据(设施码、卡号)。iClass属于MIFARE兼容智能卡,Weigand数据通常存储在卡片的特定数据块内。
解决方案:读取卡片数据块解析Weigand编码
iClass卡的Weigand 26位数据一般存储在块0x04,需通过APDU命令读取该块数据后解析。以下是PySmartCard实现代码:
from smartcard.System import readers from smartcard.util import toHexString, toBytes # 初始化读卡器连接 reader = readers()[0] conn = reader.createConnection() conn.connect() # 1. 选择HID iClass应用(AID固定为A0000003060A001800) select_apdu = [0x00, 0xA4, 0x04, 0x00, 0x0A, 0xA0, 0x00, 0x00, 0x03, 0x06, 0x0A, 0x00, 0x18, 0x00] resp, sw1, sw2 = conn.transmit(select_apdu) if sw1 != 0x90 or sw2 != 0x00: print("Failed to select iClass application") exit() # 2. (可选)验证块权限(若卡片未修改默认密钥,可跳过或使用默认密钥) # 默认密钥示例:0000000000000000 auth_apdu = [0x00, 0x88, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] resp, sw1, sw2 = conn.transmit(auth_apdu) if sw1 != 0x90 or sw2 != 0x00: print("Authentication failed, check card key") # 3. 读取块0x04数据 read_block_apdu = [0x00, 0xB0, 0x00, 0x04, 0x08] resp, sw1, sw2 = conn.transmit(read_block_apdu) if sw1 == 0x90 and sw2 == 0x00: print(f"Block 0x04 data: {toHexString(resp)}") # 解析Weigand 26位结构:1起始位 + 8设施码 + 16卡号 + 1结束位 binary_str = ''.join([format(byte, '08b') for byte in resp]) # 提取中间24位(跳过起始、结束位) weigand_data = binary_str[-26:] # 取最后26位作为Weigand完整数据 facility_code = int(weigand_data[1:9], 2) card_number = int(weigand_data[9:25], 2) print(f"Parsed Facility Code: {facility_code}, Card Number: {card_number}") else: print("Failed to read block 0x04")
关键说明
- 若读取块返回
6981错误码,说明卡片权限验证未通过,需确认卡片的访问密钥(非默认密钥需联系发卡方获取)。 - UID是卡片的硬件唯一标识,与Weigand的设施码+卡号无直接关联,不可通过UID解析得到目标参数。
内容的提问来源于stack exchange,提问作者perfo
相关产品推荐
相关产品推荐

