I tried to implement in .NET C# an utility similar to signtool.exe. To digitally sign a file, I used the classes SignedCms and CmsSigner.

CmsSigner signer;
...
SignedCms content = 
    new SignedCms(new ContentInfo(File.ReadAllBytes(aFileToSign)));
content.ComputeSignature(signer, true);

However, I am not sure how to add a timestamp received from a time server. signtool.exe has the option

signtool sign /t "time server url" ...

One possibility seems to consist in using Pkcs9SigningTime class, but I don't know how to use it correctly in conjuction with a timestamp server. All of the examples use Pkcs9SigningTime and the current time of the system. With a time server, it may be more complicated because the time server has its own certificate, and the answer will contain the time and a hash used as a countersignature.

Can anyone provide some clues about that?

Edit
Report