title: How do I read the public key from a signed C# exe
body: <p>I'm signing a dot net exe using </p>
  
  <pre><code>signcode.exe with an spc/pvk combo
  </code></pre>
  
  <p>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.</p>
  
  <p>I've tried             </p>
  
  <pre><code>X509Certificate executingCert = X509Certificate.CreateFromSignedFile(exe);
  </code></pre>
  
  <p>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.</p>
  
  <p><i>edited</i>
  Turns out the above does work.... I had my null check backwards (!= != ==) :) </p>
  
  <pre><code>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();
  }
  </code></pre>