C#将时间戳添加到PKCS#7 CMS数字签名 [英] C# Add Timestamp to PKCS#7 CMS Digital Signature

查看:334
本文介绍了C#将时间戳添加到PKCS#7 CMS数字签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名软件开发人员,负责一个使用PCKS#7对文本文件进行数字签名的项目。

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

推荐答案

与@bartonjs的评论一样,问题在于我正在将签名时间添加到未签名的属性中。更改代码以将签名时间添加到签名属性可以解决我们的问题。

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

这篇关于C#将时间戳添加到PKCS#7 CMS数字签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆