向PKCS7签名的CMS添加签名时间? [英] Add Signing Time to PKCS7 Signed CMS?

查看:204
本文介绍了向PKCS7签名的CMS添加签名时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加签名时间属性到我使用SignedCMS签名的文件。

I'm trying to add the signing time attribute to a file that I am signing using SignedCMS.

private byte[] signFile(byte[] fileContent, X509Certificate2 verificationCert)
{
   ContentInfo contentInfo = new ContentInfo(fileContent);

   SignedCms signedCMS = new SignedCms(contentInfo);

   CmsSigner cmsSigner = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, verificationCert);

   Oid signedDate = new Oid("1.2.840.113549.1.9.5"); //oid for PKCS #9 signing time 

   signedDate.Value = DateTime.Now.ToString();

   CryptographicAttributeObject cryptoAtty = new CryptographicAttributeObject(signedDate);

   cmsSigner.SignedAttributes.Add(cryptoAtty);

   signedCMS.ComputeSignature(cmsSigner, false);

   byte[] encoded = signedCMS.Encode();

   return encoded;
}

Encode上抛出的错误:

Error thrown on Encode:

CryptographicException: The object identifier is poorly formatted. 

有关如何正确添加签名时间的任何想法?我想我可能必须将签名时间转换为ASN.1编码对象,并将其添加到 cryptoAtty 的值。如何将日期/时间转换为ASN.1编码对象?

Any ideas on how to properly add the signing time? I think I may have to convert the signing time to an ASN.1 encoded object and add that to cryptoAtty's values. How would one convert the date/time to an ASN.1 Encoded object?

推荐答案

很容易。

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

这篇关于向PKCS7签名的CMS添加签名时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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