从比利时 EID 卡读取图像

Reading image from Belgian EID card

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

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

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

我的代码与下一个中的 readBinary 方法非常相似 example:

这里是:

        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;

我猜,行:

offset =  (byte)(offset + size) 

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