Cryptnox Docs

Write Data Command

This command allows write data to either a protected user memory slot (with access control) or a public custom byte area (included in SELECT response). Write data 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

Write Data (to the user protected slot, or select custom bytes)

📘

Note

  • This command writes data either to secure user memory (P1 = 0x00) in paginated format, or to public custom bytes (P1 = 0x01).
  • Secure Channel and authentication (via PIN or challenge-response) must be established.
  • Protected user memory pages must be written in order, starting from page 0.
  • Writing to public custom bytes is not protected and is visible to anyone.

📘

Prerequisites

The secure channel must be open and authentication must be successfully performed via PIN verification or challenge-response.

  • For writing user-protected memory (P1 = 0x00):
    • Previous pages must be fully written in order (e.g., page 0 before page 1).
    • The data length must be less than or equal to 1200 bytes.
  • For writing public custom bytes (P1 = 0x01):
    • The data length must be exactly 16 bytes.

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