智能卡开发-类不支持错误

问题描述 投票:0回答:1

我正在使用 ISO/IEC 7816-4 标准开发智能卡应用程序。我成功完成了Applet Selection(它使用class 00),但是当尝试PIN验证(它使用class 88)时,我遇到了6E 00响应,这对应于Class not support错误。

我有这样的要求:

IsoCase:Case3Short 类别:0x88 指令:0x11 P1-P2:0x0400 命令长度(Lc):0x04 命令数据:4 个字节,每个字节代表一个 PIN 数字 预期长度(Le):0

这里是文档链接:https://www.gnupg.org/ftp/specs/openpgp-card-2.1.pdf

这是我使用的代码,你知道可能存在什么问题以及我应该更改什么吗?

`

using System;
using PCSC;
using PCSC.Iso7816;

class Program
{
static void Main()
{
var contextFactory = ContextFactory.Instance;
using (var context = contextFactory.Establish(SCardScope.System))
{
Console.WriteLine("Currently connected readers: ");
var readerNames = context.GetReaders();
foreach (var readerName in readerNames)
{
Console.WriteLine("\\t" + readerName);
}

            using (var isoReader = new IsoReader(context, "Gemplus USB SmartCard Reader 0",                                        SCardShareMode.Shared, SCardProtocol.Any, false))
            {
                // Replace '2346' with the actual PIN you want to verify
                var pinToVerify = new byte[] { 0x01, 0x02, 0x03, 0x04 };
    
                // APDU command for PIN verification
                var apduCommand = new CommandApdu(IsoCase.Case3Short, isoReader.ActiveProtocol)
                {
                    CLA = 0x88,
                    INS = 0x11,
                    P1 = 0x04,
                    P2 = 0x00,
                    Data = pinToVerify
                };
    
                // Send the APDU command
                var response = isoReader.Transmit(apduCommand);
    
                // Check the response status word
                if (response.SW1 == 0x90 && response.SW2 == 0x00)
                {
                    Console.WriteLine("PIN verification successful!");
                }
                else if (response.SW1 == 0x63 && response.SW2 == 0x02)
                {
                    Console.WriteLine("Wrong PIN. Error response: 0x6302");
                }
                else
                {
                    Console.WriteLine($"PIN verification failed. Unexpected response: {response}");
                    Console.WriteLine("SW1 SW2 = {0:X2} {1:X2}", response.SW1, response.SW2);
                }
            }
        }
    }

}\

`

c# smartcard apdu pcsc iso-7816-4
1个回答
0
投票

以下是您可能需要检查或考虑的一些事项:

卡支持:确保您正在使用的智能卡支持您尝试发送的命令。检查卡的文档或规格,以验证它是否支持使用 88 类的 PIN 验证。

正确的 APDU 命令:仔细检查您发送的用于 PIN 验证的 APDU 命令。命令的结构必须符合您所使用的智能卡的规范。验证指令类字节 (CLA) 是否设置为 88。

卡状态:确保卡处于正确状态以接受 PIN 验证命令。某些命令可能仅在某些卡状态下有效。

PIN 格式:验证 PIN 的格式是否符合智能卡的要求。

© www.soinside.com 2019 - 2024. All rights reserved.