编程验证C#中的.EXE的数字签名

发布于 2025-02-09 10:50:51 字数 379 浏览 1 评论 0原文

在我的.dll的c#代码中,我想验证调用我.dll的.EXE的数字签名。我正在寻找一种从代码中进行signtool验证[...]之类的方法。

我要检查的数字签名显示在Windows File Explorer中的“数字签名”选项卡上。例如,这是此选项卡的示例屏幕截图。

我如何从C#代码访问.EXE的数字签名?最好的方法是什么?有人有例子吗?

within the C# code of my .dll I want to verify the digital signature of the .exe that is calling my .dll. I am looking for a way to do something like SignTool Verify [...] from code.

The digital signature I want to check is displayed on the digital signature tab in the windows file explorer. As an example, here is an example screenshot of this tab.

enter image description here

How do I access the digital signature of the .exe from C# code? What is the best way to do this? Does anyone have an example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星星的轨迹 2025-02-16 10:50:51

我使用system.security.cryptography.x509certificate进行。

X509Certificate2 cert = new X509Certificate2(X509Certificate.CreateFromSignedFile(fileInfo.FullName));
if (!cert.Verify())
{
    Console.WriteLine("invalid cert: " + fileInfo.Name);
}
else
{
    Console.WriteLine("Cert for file is valid: " + fileInfo.FullName);
}

I use System.Security.Cryptography.X509Certificates to do it.

X509Certificate2 cert = new X509Certificate2(X509Certificate.CreateFromSignedFile(fileInfo.FullName));
if (!cert.Verify())
{
    Console.WriteLine("invalid cert: " + fileInfo.Name);
}
else
{
    Console.WriteLine("Cert for file is valid: " + fileInfo.FullName);
}
时光礼记 2025-02-16 10:50:51

我使用反思比较证书。
如下样品:

string dllPath = "";
Assembly assembly = Assembly.LoadFile(dllPath);
var modules = assembly.GetModules();
var cert = modules[0].GetSignerCertificate();

I use reflection to compare the cert.
Sample like below:

string dllPath = "";
Assembly assembly = Assembly.LoadFile(dllPath);
var modules = assembly.GetModules();
var cert = modules[0].GetSignerCertificate();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文