This command allows writing data to either a protected user memory slot (with access control) or a public custom byte area (included in SELECT response). Writing to protected slots requires authentication via PIN or challenge-response and must occur over a Secure Channel.
def write_data(P1: Int, data: bytes, P2: Int):
card.write_data(P1, data, P2)
For example, write_data(0, b"Antoine DATA Card" * 12, 0)
Application Protocol Data Unit (APDU) Components
The following table outlines the components of the Application Protocol Data Unit (APDU).
Field | Description | Value |
CLA | This field specifies the class of the instruction. | 0x80 |
INS | This field specifies the particular command or operation that the smart card or secure element should execute. | 0xFC |
P1 | First parameter of the instruction that specifies the details about the operation being requested. | 0x00 or 0x01 |
P2 | First parameter of the instruction that specifies additional details about the operation being requested. | 0x00 (or page index) |
Data | Key data | Data to be written (to the user protected slot, or select custom bytes) |
📘 Note
📘 Prerequisites
The secure channel must be open and authentication must be successfully performed via PIN verification or challenge-response.
Response
The following table outlines the possible responses that you will receive:
Response Code | Description |
0x9000 | Success |
0x6985 | The PIN is not validated or user challenge-response not performed or previous data pages not fully written |
0x6700 | Data length incorrect (> 1200 bytes P1=0, or !=16 when P1=1) |
0x6A86 | P1 not 0 nor 1, or P2 out of range |
0x6982 | outside the secure channel if data is too large |