Add Signing Time to PKCS7 Signed CMS?

人盡茶涼 提交于 2020-01-01 10:14:09

问题


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

Error thrown on Encode:

CryptographicException: The object identifier is poorly formatted. 

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?


回答1:


Well that was easy.

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


来源:https://stackoverflow.com/questions/3513162/add-signing-time-to-pkcs7-signed-cms

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