如何阅读从签署C#EXE公钥

编程入门 行业动态 更新时间:2024-10-11 23:24:38
本文介绍了如何阅读从签署C#EXE公钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我用

签署了点网的exe

signcode.exe与SPC / PVK组合

的文件需要读取在运行它自己的公共密钥,以便验证一些数据。我已经下了许多不同的途径。

我试过

X509证书executingCert = X509Certificate.CreateFromSignedFile(EXE);

executingCert然后空。我猜signcode不创建一个X509签名的文件,但如果有改变,我很高兴地走那条路的开关。

编辑 原来上面没有工作....我有我的空检查向后(!=!= = =):)

大会ASM = Assembly.GetExecutingAssembly(); 串EXE = asm.Location; x509证书executingCert = X509Certificate.CreateFromSignedFile(EXE); 如果(!executingCert = NULL) { Console.WriteLine(集结号签订); 字节[] = assemblyKey executingCert.GetPublicKey(); }

解决方案

SignCode(对于.NET 1.0和1.1)使用验证码签名,其中据​​我所知,缺乏.Net框架管理接口。你可能会需要使用P / Invoke来调用Win32 API的程序,如在此发现KB文章:如何从验证码信息签名的可执行。可能你会需要使用 CryptQueryObject 这将让你的证书,然后你会很可能不得不寻找另一个例程拉从公开密钥。

看看这个相关的StackOverflow问题,其中有很多答案:来的WinVerifyTrust检查特定签名

I'm signing a dot net exe using

signcode.exe with an spc/pvk combo

The file needs to read its own Public Key at runtime in order to verify some data. I've gone down a number of different avenues.

I've tried

X509Certificate executingCert = X509Certificate.CreateFromSignedFile(exe);

executingCert is then null. I'm guessing signcode isn't creating an X509 signed file, though if there's a switch to change that I'm happy to go that way.

edited Turns out the above does work.... I had my null check backwards (!= != ==) :)

Assembly asm = Assembly.GetExecutingAssembly(); string exe = asm.Location; X509Certificate executingCert = X509Certificate.CreateFromSignedFile(exe); if (executingCert != null) { Console.WriteLine("Assembly is signed"); byte[] assemblyKey = executingCert.GetPublicKey(); }

解决方案

SignCode (for .Net 1.0 and 1.1) uses Authenticode signing, which as far as I'm aware, lacks a .Net Framework managed interface. You will likely need to use P/Invoke to call routines in Win32 API such as those found in this KB article: How To Get Information from Authenticode Signed Executables. Likely you'll need to use CryptQueryObject which will get you the certificate, which you will then likely have to find another routine to pull the public key from.

Check out this related StackOverflow question which has a lot of answers: WinVerifyTrust to check for a specific signature?

更多推荐

如何阅读从签署C#EXE公钥

本文发布于:2023-11-13 05:59:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583634.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:公钥   EXE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!