简体   繁体   中英

C# Add Timestamp to PKCS#7 CMS Digital Signature

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???

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM