解密 GPG 消息时出现 mdc 错误
我有一个客户端和服务器系统,定期运行计划任务并通过 gpg 加密的 xml 文件进行通信。所有必需的公钥已在客户端和服务器之间成功交换。加密和解密调用是通过批处理文件完成的。
加密语法
gpg.exe --batch --yes --recipient %1 --output %4 --passphrase %5 --local-user %2 --sign --encrypt %3
解密语法
gpg.exe --batch - -yes --output %3 --passphrase %4 --decrypt %2 2>%1
客户端创建一个 xml 文件,使用服务器公钥通过 gpg 对其进行加密,使用私钥进行签名并将其上传到服务器的 ftp 站点。服务器定期检查 ftp 文件夹中是否有新文件。对于任何新文件,它都会使用 gpg 进行解密,然后处理文件内的 xml。
对于服务器尝试解密的某些 xml 文件,我收到如下错误:
gpg: block_filter 00AA8400: 读取错误 (size=7841,a->size=395)
gpg:mdc_packet 编码无效
gpg:解密失败:数据包无效
gpg:block_filter:待处理字节!
需要注意的是,这种情况并非发生在所有文件上,而是仅发生在某些文件上。我无法在失败的文件之间找到任何共同点。
有人熟悉这个错误的含义吗?欢迎提出任何有助于追踪此问题的建议。
I have a client and server system that regularly run scheduled tasks and communicate through xml files that have been encrypted by gpg. All required public keys have been successfully exchanged between the client and server. The encryption and decryption calls are being done from a batch file.
encrypt syntax
gpg.exe --batch --yes --recipient %1 --output %4 --passphrase %5 --local-user %2 --sign --encrypt %3
decrypt syntax
gpg.exe --batch --yes --output %3 --passphrase %4 --decrypt %2 2>%1
The client creates a xml file, encrypts it with gpg using server public key, signs with private key and uploads it to the server's ftp site. Server regularly checks for new files in ftp folder. For any new file it decrypts using gpg and then processes the xml inside the file.
For some of the xml files that the server tries to decrypt, I receive an error as follows:
gpg: block_filter 00AA8400: read error (size=7841,a->size=395)
gpg: mdc_packet with invalid encoding
gpg: decryption failed: invalid packet
gpg: block_filter: pending bytes!
The point to note is that this is not happening with all the files but with only some files. I haven't been able to find any commonality between the files that it fails on.
Is anyone familiar to what this error means? any suggestions to help track this down are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于想通了。 gpg 不是这里的罪魁祸首。当服务器检查指定文件夹中的文件时,它使用Delphi上的Append(fileHandler)方法来测试文件是否可以打开。但这个方法有一个特殊的条件,如果它在文件的最后 128 字节块中找到了 ascii 字符 26(即 CTRL+z),它将删除该字符中的所有内容,直到文件末尾。这导致部分加密文件被删除,随后在通过gpg解密时出现上述错误。当我用 Reset(fileHandler) 替换 Append 方法后,加密文件不再被修改,并且解密工作完美。
Finally figured it out. gpg was not the culprit here. when the server was checking for files in the specified folder, it was using the Append(fileHandler) method on Delphi to test if the file could be opened. But this method had a peculiar condition as if it found the ascii character 26 (i.e. CTRL+z) in the last 128 byte block of the file, it would remove everything from that character till the end of the file. This caused some part of the encrypted files to be deleted and subsequently caused the above error when decrypting it through gpg. After I replaced the Append method with Reset(fileHandler), encrypted files were no longer modified and decryption works perfectly.