C# Add Timestamp to PKCS#7 CMS Digital Signature

為{幸葍}努か 提交于 2020-08-25 12:16:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!