简体   繁体   中英

How to send a PIN verification CODE to a smartcard using APDU - Using .NET

I am able to connect to the card and now I need to verify the PIN but I´m not able to figure out which code should I use to perform the verification

// Verify PIN
//HERE IS WHAT I´M NOT SURE WHAT TO USE - Just an Example
byte[] pin = new byte[] { 0x31, 0x32, 0x33, 0x34, 0xFF, 0xFF, 0xFF, 0xFF };
APDUParam apduParam = new APDUParam();
apduParam.Data = pin;
apduVerifyCHV.Update(apduParam);
apduResp = iCard.Transmit(apduVerifyCHV);

It is a smart card that uses an 7 digits PIN. It is always 7 digits.

**Example:**
{CLA, INS, P1, P2, Lc, b1, b2, b3, b4, b5, b6, b7}

Here I have the basic CLA , INS , P1 , P2 , LC bytes. Should I set + 3 bytes or 6 bytes for the PIN of 7 digits And shall be the actual PIN or just a 0xFF value

Ex. {CLA, INS, P1, P2, Lc, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} +7 Bytes

in the spec I found examples for 8 Digits min and max and min 4 and max 12 bytes...

This is simpler than I tought...

When PIN uses ASCII format conversion with padding

PIN entered is 1357 (min size =4 and max size=8 digits)

  • • Left justification
  • • Default display behavior for the CCID
  • • The CCID sends to the ICC the command

    CLA INS P1 P2 Lc 31 33 35 37 FF FF FF FF

When PIN uses BCD right justification and control field

PIN entered is 13579 (min size =4 and max size=8 digits)

  • • Right justification. The personal code contains less than 8 digits; therefore, the most significant digits of the eight-digit code must be filled with zeroes.
  • • The frame integrates a specific control field “01” before the PIN conversion.
  • • No messages
  • • The CCID sends to the ICC the command

    CLA INS P1 P2 Lc 01 00 01 35 79

so, all I had to do was to set the proper values. In my case using ASCII method with left justification:

0x00 0x20 0x00 0x01 0x08 0x30 0x31 0x34 0x37 0x34 0x31 0x30 0xFF

3 - refers to the padding

3x - x refers to the actual pin number at a given position (left justification) as I have a PIN of 7 digits the bytes not used shall default to 0xFF

Hope that helps some one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM