我们需要验证二进制文件是否使用数字签名(Authenticode)正确签名.这可以通过signtool.exe轻松实现.但是,我们需要一种自动方式来验证签名者名称和时间戳.这在使用CryptQueryObject()API的本机C++中是可行的,如以下精彩示例所示:如何从Authenticode签名的可执行文件获取信息
然而,我们生活在一个托管的世界:)因此寻找相同问题的C#解决方案.直接的方法是pInvoke Crypt32.dll,一切都完成了.但是System.Security.Cryptography.X509CertificatesNamespace中有类似的托管API .X509Certificate2类似乎提供了一些信息但没有时间戳.现在我们来到原始问题,我们如何才能在C Sharp中获得数字签名的时间戳?
我正在为安装程序DLL编写一个函数来验证已安装在系统上的EXE文件的Authenticode签名.
该功能需要:
A)验证签名是否有效.
B)验证签名者是我们的组织.
因为这是在安装程序,因为这需要运行在旧的Win2k设施,我不想要依靠的CAPICOM.dll,因为它可能不是在目标系统上.
该的WinVerifyTrust API的伟大工程,以解决(A).
我需要找到一种方法来比较已知证书(或其中的属性)与签署有问题的EXE的证书.
我正在签署一个dot net exe
signcode.exe with an spc/pvk combo
Run Code Online (Sandbox Code Playgroud)
该文件需要在运行时读取自己的公钥以验证某些数据.我走了很多不同的途径.
我试过了
X509Certificate executingCert = X509Certificate.CreateFromSignedFile(exe);
Run Code Online (Sandbox Code Playgroud)
executionCert则为null.我猜测signcode没有创建一个X509签名文件,但如果有一个改变的转换,我很高兴这样做.
编辑 结果以上工作....我向后检查了我的空检查(!=!= ==):)
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();
}
Run Code Online (Sandbox Code Playgroud) authenticode ×2
c# ×2
.net ×1
c++ ×1
certificate ×1
cryptography ×1
public-key ×1
signature ×1
signtool ×1
winapi ×1
x509 ×1