【问题标题】:Reading image from Belgian EID card从比利时 EID 卡读取图像
【发布时间】:2020-01-02 13:26:17
【问题描述】:

当我使用卡中的 APDU 命令读取 EF(ID#RN) 文件时 - 一切都很好。 但是当我试图读取图像文件EF(ID#Photo) 时,图像会被裁剪。我只能正确读取前 510-512 个字节。

文件读取操作总是返回 90-00 - 成功响应。所以,我设置文件大小限制(到 3064 字节)以停止读取操作。

在 google 群组中读到它可能与交易有关。但我的平台是 UWP,Windows.Devices.SmartCards 命名空间不支持事务。可以确保卡上的图像没有损坏(因为它可以被第三方软件读取)。

我的代码和下一个example中的readBinary方法很相似:

这里是:

        List<byte> resultBytes = new List<byte>();
        byte offset = 0x00;
        byte size = 0xFF;

        var fileBytes = await GetBytes(card, new byte[] { 0x00, 0xB0, (byte)(offset >> 8), (byte)(offset & 0xFF), size });

        if (fileBytes[0] == 0x6C)
        {
            size = fileBytes[1];
            fileBytes = await GetBytes(card, new byte[] { 0x00, 0xB0, (byte)(offset >> 8), (byte)(offset & 0xFF), size });
        }

        while (fileBytes[fileBytes.Length - 2] == 0x90 && fileBytes[fileBytes.Length - 1] == 0x00)
        {
            if (resultBytes.Count >= maxSize && maxSize > 0) break;

            var newBytes = fileBytes.ToList();
            newBytes.RemoveRange(fileBytes.Length - 2, 2);
            resultBytes.AddRange(newBytes);

            if (maxSize > 0 && resultBytes.Count > maxSize - size) size = (byte)(maxSize - resultBytes.Count);

            offset = (byte)(offset + size);

            fileBytes = await GetBytes(card, new byte[] { 0x00, 0xB0, (byte)(offset >> 8), (byte)(offset & 0xFF), size });

            if (fileBytes[0] == 0x6C)
            {
                size = fileBytes[1];
                fileBytes = await GetBytes(card, new byte[] { 0x00, 0xB0, (byte)(offset >> 8), (byte)(offset & 0xFF), size });
            }
        }

        return resultBytes;

【问题讨论】:

  • 您好,请提供您编写的代码。在您给出的示例中,代码语言是 Java。
  • @guidot,你完全正确。您可以将其添加为答案。偏移量应为 int 类型

标签: uwp smartcard apdu smartcard-reader eid


【解决方案1】:

我猜,这行:

offset =  (byte)(offset + size) 

是问题所在。如果转换为字节,偏移量如何增加?

【讨论】:

    猜你喜欢
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 2011-12-02
    • 1970-01-01
    相关资源
    最近更新 更多