The command allows secure data decryption or symmetric key derivation using an internal EC key from the device’s BIP32 seed tree. Inspired by OpenPGP smartcards, it enables asymmetric encryption and decryption using a fixed derivation path, ensuring that only the private key securely stored on the card can the content using the corresponding public key.
Table of Contents
ToggleThis command supports two operational modes:
def decrypt(pub_key: Any, PIN: str):
card.decrypt(pub_key, PIN)
# For example:
decrypt(pub_key, "123456")
📘
Note
- A secure channel must be opened.
- Either PIN authentication or user signature authentication is required.
- The card must have a seed or extended key loaded before using this command.
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. | 0xC4 |
P1 | First parameter of the instruction that specifies the details about the operation being requested. | provide symmetric key OR decryption in card |
Data | Key data | PIN (in case not user auth) | PubKey | dataEncrypted (when P1=1) |
Condition | Data Value |
P1 = 0x00 & Secure Channel Opened & No User Auth (PIN required) & Data Length = 74 bytes |
|
P1 = 0x00 & Secure Channel Opened & User Authenticated via Signature (no PIN) & Data Length = 65 bytes |
|
P1 = 0x01 & Secure Channel Opened & No User Auth (PIN required) & Data Length ≥ 74 bytes & EncData % 16 == 0 |
|
P1 = 0x01 & Secure Channel Opened & User Authenticated via Signature (no PIN) & Data Length ≥ 65 bytes & EncData % 16 == 0 |
|
📘
Note
- PubKey Format: Must be 65 bytes in X9.62 uncompressed format: 0x04 | X (32B) | Y (32B)
- Encrypted Data (EncData): Must be padded to 16-byte boundaries (AES block size)
- PIN: Right-padded with 0x00 to 9 bytes if present
- PIN Effects:
- If correct: state changes to "authed"
- If incorrect: state resets (user auth invalidated)
The following table outlines the possible responses that you will receive:
Response Code | Description |
0x9000 | Success |
0x6A80 | the data length is not correct |
0x6985 | no key/seed loaded |
0x63Cx | the PIN is not correct |
0x6982 | (outside secure channel) the data input length is far too long |