问题
I am a software developer in charge of a project to digitally sign text files with PCKS#7.
There is a third party in charge of analysing the signed file to tell us if it's correct or not.
The issue I'm having is that they say the signer info does not contain a timestamp. They assured me I do not need to hire an outside trusted server for the timestamp, that the server's timestamp would be enough.
I have scoured the internet and came up with the following code to try and add the timestamp but the third party responsible for checking the files says the issue is still occurring.
private byte[] Sign(byte[] content)
{
CmsSigner cmsSigner = new CmsSigner(_cert);
cmsSigner.UnsignedAttributes.Add(new Pkcs9SigningTime(DateTime.Now));
SignedCms signedCms = new SignedCms(new ContentInfo(content));
signedCms.ComputeSignature(cmsSigner, true);
return signedCms.Encode();
}
This is what I have written so far regarding the digital signature. The line added for the timestamp would be the second one:
cmsSigner.UnsignedAttributes.Add(new Pkcs9SigningTime(DateTime.Now));
I am out of ideas and cannot, for the life of me, find useful documentation of this.
How can I append the timestamp to the Signer Info???
回答1:
As with @bartonjs's comment, the problem was I was adding the signing time into the unsigned attributes. Altering the code to add the signing time to the signed attributes resolved our issues.
cmsSigner.SignedAttributes.Add(new Pkcs9SigningTime(DateTime.Now));
来源:https://stackoverflow.com/questions/59829810/c-sharp-add-timestamp-to-pkcs7-cms-digital-signature