如何解决SW=6985 读取电子护照中间错误DG5、DG7
我正在开发用于读取 Epassport 数据的 Xamarin.Android 应用程序,但遇到了以下问题: 通常当我在阅读中间使用安全消息大数据组 (DG5,DG7) 阅读时,Epassport 给出 RAPDU = 6985 (0x6985,0x69 0x85),但有时一切正常(约 65% 的情况)。
我试过写 isoDep.SetTimeout(2000);但这没有帮助,SSC 在 VerificationMessage 和 SendSecureMessageAPDU 中总是正确递增,KS_Enc 和 KS_MAC 不改变,我不知道为什么 Epassport 给我 6985,帮帮我
// Read first 4 bytes for FileLength
byte[] Header4,Header5;
DO97 = new byte[] { 0x97,0x01,0x80 }; // 0x80 = 126
byte i = 0;
//RAPDU length of data Epassport = 255 but need 256,so 256 = 128 * 2;
// Problem arises here in WHILE
while (i != FileLength[0] && FileLength.Length >= 2) // Need for big files (DG5 photo /DG7 signature)
{
//Read first 128 bytes
Header4 = new byte[] { 0x0C,0xB0,i,0x04,0x80,0x00,0x00 }; // offset 0x04 because first 4 bytes for lenght
var result4 = SendSecureMessageAPDU(Header4,DO97); // ERROR HERE
VerificationRAPDU(result4);
Data_DG = Data_DG.Concat(TripleDES(TripleDESMode.Decoding,result4,KS_Enc)).SkipLast(24).ToArray();
//Read last 128 bytes
Header5 = new byte[] { 0x0C,0x84,0x00 };
var result5 = SendSecureMessageAPDU(Header5,DO97); // OR ERROR HERE !!!!!
VerificationRAPDU(result5);
Data_DG = Data_DG.Concat(TripleDES(TripleDESMode.Decoding,result5,KS_Enc)).SkipLast(24).ToArray();
i++;
}
// For short file (Length <255 bytes) and last block bigfile ( where length also <255 bytes)
byte[] Header6 = new byte[] { 0x0C,0x00 };
// Header6 = new byte[] { 0x0C,0x00 };
if (FileLength.Length > 1)
{
DO97 = new byte[] { 0x97,FileLength[1] };
}
else
{
DO97 = new byte[] { 0x97,FileLength[0] };
}
var result6 = SendSecureMessageAPDU(Header6,DO97);
VerificationRAPDU(result6);
Data_DG = Data_DG.Concat(TripleDES(TripleDESMode.Decoding,result6,KS_Enc)).SkipLast(16).ToArray();
string testDG = BitConverter.ToString(Data_DG).Replace("-","");
var asddas = Encoding.UTF8.GetString(Data_DG);
return Data_DG;
}
public byte[] SendSecureMessageAPDU(byte[] Header,byte[] buildDO)
{
byte[] M = Header.Concat(buildDO).ToArray();
// Вычисление MAC от M:
string sM = BitConverter.ToString(M);
if (SSC[SSC.Length - 2] == 255)
{
SSC[SSC.Length - 3]++;
SSC[SSC.Length - 2]++;
SSC[SSC.Length - 1]++;
}
else if (SSC[SSC.Length - 1] == 255)
{
SSC[SSC.Length - 2]++;
SSC[SSC.Length - 1]++;
}
else
SSC[SSC.Length - 1]++;
byte[] N = SSC.Concat(Header)
.Concat(buildDO)
.ToArray();
byte[] CC = MAC(N,KS_MAC);
byte[] DO8E = new byte[] { 0x8E,0x08,};
DO8E = DO8E.Concat(CC).ToArray();
string sD08E = BitConverter.ToString(DO8E);
// build secure command
var command = Header.Take(4).ToArray()
.Concat(new byte[] { (byte)(buildDO.Length + DO8E.Length) }) // Length
.Concat(buildDO)
.Concat(DO8E)
.Concat(new byte[] { 0x00 })
.ToArray();
var result = isoDep.Transceive(command).ToArray(); // Error RAPDU = 6985
if (result.Length == 2)
{
throw new RAPDU_Exception("Error RAPDU ePassport");
}
return result;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。