无法从存储卡SLE5528读取

时间:2019-05-18 12:17:20

标签: c# winforms smartcard apdu pcsc

我还是接触卡和读卡器的新手。我正在使用C#来构建与ACR38U智能卡读取器集成的应用程序,并且我有SLE5528存储卡。我正在使用以下示例为存储卡(在这种情况下为22222)中赋予唯一ID:

    int indx;

    tmpStr = "22222";
    ClearBuffers();

    SendBuff[0] = 0xFF;
    SendBuff[1] = 0xD0;
    SendBuff[2] = 0xA1;
    SendBuff[3] = 0x00;
    SendBuff[4] = 0x08;

    for (indx = 0; indx <= tmpStr.Length - 1; indx++)
    {
        if ((Convert.ToByte(tmpStr[indx])) != 0x00)
            SendBuff[indx + 5] = Convert.ToByte(tmpStr[indx]);
    }

    SendBuffLen = SendBuff[4] + 5;
    RecvBuffLen = 2;
    tmpStr = "";

    for (indx = 0; indx <= SendBuffLen - 1; indx++)
    {
        tmpStr = tmpStr + string.Format("{0:x2}", SendBuff[indx]).ToUpper() + " ";
    }

    retcode = SendAPDUandDisplay(0, tmpStr);

    if (retcode != ModWinsCard64.SCARD_S_SUCCESS)
    {
        return;
    }

    tData.Text = "";

从那里我得到90 00的响应,这意味着成功。现在我用这个来读取存储卡:

    int indx;

    tData.Text = "";
    ClearBuffers();

    SendBuff[0] = 0xFF;
    SendBuff[1] = 0xB0;
    SendBuff[2] = 0xA1;
    SendBuff[3] = 0x00;
    SendBuff[4] = 0x08;

    SendBuffLen = 5;
    RecvBuffLen = SendBuff[4] + 2;
    tmpStr = "";

    for (indx = 0; indx <= SendBuffLen - 1; indx++)
    {
        tmpStr = tmpStr + string.Format("{0:x2}", (SendBuff[indx])).ToUpper() + " ";
    }

    retcode = this.SendAPDUandDisplay(2, tmpStr);

    if (retcode != ModWinsCard64.SCARD_S_SUCCESS)
    {
        return;
    }

    // 3. Display data read from card into Data textbox
    tmpStr = "";

    for (indx = 0; indx <= SendBuff[4] - 1; indx++)
    {
        tmpStr = tmpStr + Convert.ToChar(RecvBuff[indx]);
    }
    tData.Text = tmpStr;

    byte[] buffer = new byte[RecvBuffLen];

    for (int i = 0; i < RecvBuffLen; i++)
    {
        buffer[i] = RecvBuff[i];
    }

    byte[] buffer2 = new byte[8];
    for (int i = 0; i < buffer2.Length; i++)
    {
        if (buffer.Length > i)
            buffer2[i] = buffer[i];
    }

    int iCardID = BitConverter.ToInt32(buffer2, 0);
    MessageBox.Show(iCardID.ToString());

但是iCardID始终是-1而不是22222。关于我在哪里做错的任何想法?也许我写错了。

0 个答案:

没有答案