Verify digital signature programmatically

By | February 7, 2021

It is continuation of “Signing Windows PE file on Linux” post to verify digital signature programmatically. For demonstration, I am using a previously signed usb-cubby-signed.exe file on Linux with self-signed certificate and Windows .Net API from X509Certificates namespace. The C# console application which determines if application is signed and presents certificate issuer if certificate has been found is below:


using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
namespace digSignature
{
   class Program
   {
      static void Main(string[] args)
      {
         if (args.Length == 0)
         {
            Console.WriteLine("Specify executile file as argument.");
            return;
         }
         if(!File.Exists(args[0]))
         {
            Console.WriteLine("ex.Message");
            return;
         }
         try
         {
            X509Certificate certificate = X509Certificate.CreateFromSignedFile(args[0]);
            if (certificate != null)
            {
               Console.WriteLine(certificate.Issuer);
            }
         }
         catch (Exception ex)
         {
            Console.WriteLine(ex.Message);
            return;
         }
      }
   }
}

Results:
Certificate Issuer)


Leave a Reply

Your email address will not be published. Required fields are marked *