Skip to main content

Storing objects on smartcard

In this section, we will store a file on smart card and then get it back.

Here is our test.txt file:

$ cat test.txt
This is a test.

Let us query the auth ID of the PIN that protects this key:

$ pkcs15-tool --list-pins
Using reader with a card: Feitian SCR301 01 00
PIN [User PIN]
Com. Flags: 0x3
ID : 01
Flags : [0x30], initialized, needs-padding
Length : min_len:4, max_len:16, stored_len:16
Pad char : 0x00
Reference : 1
Type : ascii-numeric
Path :

To store the file on smart card with auth ID 01:

$ pkcs15-init -W test.txt -a 01 -l "Fichier test"
Using reader with a card: Feitian SCR301 01 00
User PIN required.
Please enter User PIN:

After entering PIN, the file is stored on smart card.

To list files on card:

$ pkcs15-tool --list-data-objects
Using reader with a card: Feitian SCR301 01 00
Reading data object <0>
applicationName: pkcs15-init
Label: Fichier test
applicationOID: NONE
Path: 3f0050153300
Auth ID: 01
Data Object (16 bytes): < 54 68 69 73 20 69 73 20 61 20 74 65 73 74 2E 0A >

Now, we open the file:

$ pkcs15-tool --read-data-object "Fichier test" -o welcome-back.txt

Let's display content:

$ cat welcome-back.txt
This is a test.