How to send a PIN verification code to a smart card using APDU - Using .NET

I can connect to the card, and now I need to check the PIN code, but I can’t determine which code to use to perform the check

// 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); 

This is a smart card that uses a 7-digit PIN. It is always 7 digits.

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

Here I have the basic bytes CLA , INS , P1 , P2 , LC . Should I set + 3 bytes or 6 bytes for a 7-digit PIN code And should there be an actual PIN code or just the value 0xFF

 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 ...

+4
source share
1 answer

It's easier than me ...

When the PIN code uses ASCII conversion with padding

PIN entered: 1357 (minimum size = 4 and maximum size = 8 digits)

  • β€’ Left excuse
  • β€’ Default display behavior for CCID
  • β€’ CCID sends a command to ICC

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

When the PIN uses the right alignment and BCD control field

PIN entered: 13579 (minimum size = 4 and maximum size = 8 digits)

  • β€’ The right rationale. The personal code contains less than 8 digits; therefore, the most significant digits of the eight-digit code must be filled with zeros.
  • β€’ The frame integrates the defined control field β€œ01” before the PIN conversion.
  • β€’ No messages
  • β€’ CCID sends a command to ICC

    CLA INS P1 P2 Lc 01 00 01 35 79

So all I had to do was set the correct values. In my case using the ASCII method with left excuse:

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

3 - refers to the addition

3x - x refers to the actual contact number in this position (left justification) since I have a PIN code of 7 digits, bytes that are not used are 0xFF by default

Hope this helps someone

+3
source

All Articles