C#:如何检测authenticode签名文件的篡改
我正在尝试编写一个 C# 程序来验证 exe 的数字签名。这些exe文件是用authenticode证书签名的,我想检测篡改。
我已经能够创建一个 SignedCms 实例,如下所述: 获取时间戳来自 .NET 中的 Authenticode 签名文件
我认为 SignedCms.CheckSignature 可以解决问题,但此方法永远不会引发异常...即使当我修改 exe 的某些位时也不会...
I'm trying to write a C# program that verifies the digital signature of exe's. The exe's are signed with an authenticode certificate, and I want to detect tampering.
I've been able to create a SignedCms instance as described here: Get timestamp from Authenticode Signed files in .NET
I assumed SignedCms.CheckSignature would do the trick, but this method never throws an exception... Even not when I modify some bits of the exe...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您已经浏览了 .NET Framework 文档,但没有找到您需要的内容。 这个 StackOverflow 问题的答案有一个链接,描述了如何使用本机 Windows CryptQueryObject 函数来验证签名。因此,剩下的就是查看 PInvoke.NET 以了解如何将该功能引入 . NET。
I'm assuming you've scoured the .NET Framework docs and didn't find what you needed. The answer to this StackOverflow question has a link that describes how to use the native Windows CryptQueryObject function to verify a signature. So all that's left is to check out PInvoke.NET to see how to bring that function into .NET.
您可以直接 shell 到
signtool.exe /verify
并检查结果吗?我最近编写了一个简单的应用程序,它使用相同的方法对可执行文件进行签名,并且效果很好。
MSDN 上的 Signtool
Could you just shell to
signtool.exe /verify
, and check the result?I recently wrote a simple app which signs executables using the same method, and it works great.
Signtool on MSDN