Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# verify file certificate

I want to verify file certificate. The signature was generating using sha1 and RSA. When right clicking the file, selecting properties, Digital Signatures, Details I see the following:

enter image description here

I have C++ code that verifies such a signature, using WinVerifyTrust.

However I googled - I just couldn't find C# way of doing it. I tried to export the certificate to file, and then took from the file properties the Message Digest: enter image description here Create X509 Certificate, and verify hash - nothing worked.

Any help will be appreciated.

CLARIFICATION

In short: Given a file, how can I verify it is signed by a trusted certificate?

like image 234
sara Avatar asked Apr 15 '26 19:04

sara


1 Answers

You are looking for : X509Certificate.CreateFromSignedFile

 try
  {
  X509Certificate theSigner = X509Certificate.CreateFromSignedFile("c:\\r\\1.dll");
  Console.Write("certificate info :"+ theSigner.GetCertHashString());
  }
  catch (Exception ex)
  {
         Console.WriteLine("No digital signature ");


  }
like image 172
Royi Namir Avatar answered Apr 18 '26 08:04

Royi Namir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!