[英]How to write smart card with pyscard
I'm using reader/writer acr38f and my smart card is SLE4418.我正在使用读写器 acr38f,我的智能卡是 SLE4418。 How do I read and write text to my smart card?
如何在智能卡中读取和写入文本?
For example: Hello World!
例如:
Hello World!
apdu = [0XFF, 0X20,0x00,0x00,0x02, 0x00, 0x00]
apdu = [0XFF, 0X20,0x00,0x00,0x02, 0x00, 0x00]
response, sw1, sw2 = cardservice.connection.transmit( apdu )
响应,sw1,sw2 = cardservice.connection.transmit(apdu)
apdu = [0XFF,0xA4,0x00,0x00,0x01,0x05] response, sw1, sw2 = cardservice.connection.transmit( apdu ) apdu = [0XFF,0XB2,0X00,0xA7,0X09] response, sw1, sw2 = cardservice.connection.transmit( apdu ) print response apdu = [0XFF, 0XD0,0x00,0xA7,0x09,0xA7,0x02,0xA7,0x02,0xA7,0x02,0xA7,0x02,0xA7] response, sw1, sw2 = cardservice.connection.transmit( apdu )
card response:卡片回复:
connecting to ACS CCID USB Reader 0
ATR 3B 04 92 23 10 91
> FF 20 00 00 02 00 00
< 00 00 00 90 0
> FF A4 00 00 01 05
< [] 90 0
> FF B2 00 A7 09
< FF FF FF FF FF FF FF FF FF 90 0
[255, 255, 255, 255, 255, 255, 255, 255, 255]
> FF D0 00 A7 09 A7 02 A7 02 A7 02 A7 02 A7
< [] 90 0
I do not have the hardware to test this, but this should get you going:我没有硬件来测试这个,但这应该让你继续:
Communicating with smart cards involves sending APDU (Smart Card application protocol data unit) commands and receiving APDU responses.与智能卡通信涉及发送 APDU (智能卡应用协议数据单元)命令和接收 APDU 响应。
Command APDUs are sent through the reader/write (your ACR38F) and consists of a 4-byte header followed by data (and info about the data size and response size)命令 APDU 通过读/写器(您的 ACR38F)发送,由 4 字节 header 后跟数据(以及有关数据大小和响应大小的信息)组成
Field Len Description
--------------------------------------------
CLA (1) Instruction Class
INS (1) Instruction Code
P1-P2 (2) Instruction Parameters
Lc (0,1,3) Number of data bytes to follow
DATA (*) Data to be transmitted
Le (0-3) Maximum response bytes
The response consists of:响应包括:
Field Len Description
--------------------------------------------
DATA (*) Data to be transmitted
SW1-SW2 (2) Command status
In the case of the SLE4418, in order to write data, the values should be as follows:对于SLE4418,为了写入数据,值应如下所示:
So therefore in code:因此,在代码中:
WRITE = [0x00, 0xD6]
STARTMSB = [0x00] #change to where on the card you would like to write
STARTLSB = [0x00] #same here
MEM_L = [0x01]
DATA = [0x01]
cardservice.connection.connect()
apdu = READ + STARTMSB + STARTLSB + MEM_L + DATA
response1, sw1, sw2 = self.cardservice.connection.transmit( apdu )
Other relevant info:其他相关信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.