简体   繁体   English

C# 向 PKCS#7 CMS 数字签名添加时间戳

[英]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.我是一名软件开发人员,负责使用 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.与@bartonjs 的评论一样,问题是我将签名时间添加到了 unsigned 属性中。 Altering the code to add the signing time to the signed attributes resolved our issues.更改代码以将签名时间添加到签名属性解决了我们的问题。

cmsSigner.SignedAttributes.Add(new Pkcs9SigningTime(DateTime.Now));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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