Reputation: 57
I am assigned to implement a windows-based C# program to pickup a folder and use signtool.exe to scan/sign all documents.
I am able to get the list of the files in that folder. Now how do I use the signtool.exe to sign them? The client machines don't have the signtool.exe installed anywhere.
Edited: Instead of using external tool to do signature check, I could use the x509Certificates to check directly. My solution is below for whoever needs in the future.
Upvotes: 0
Views: 469
Reputation: 57
Sorry, it has been a while. I found a simple solution for this. Just hope in the future, people would look for it:
public static string CheckSignature(string FileName)
{
//X509Certificate2 cert;
try
{
var signer = X509Certificate.CreateFromSignedFile(FileName);
var cert = new X509Certificate2(signer);
return "Digitally signed by: " + cert.SubjectName.Name;
}
catch (Exception)
{
return "NOT digitally signed.";
}
}
Don't forget including: using System.Security.Cryptography.X509Certificates;
JPL
Upvotes: 1
Reputation: 1963
You would launch signtool.exe with code similar to:
var info = new ProcessStartInfo("<path.to>\signtool.exe", "<command line arguments>");
var p = Process.Start(info);
p.WaitForExit();
Upvotes: 1