Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否向PKCS7签名CMS添加签名时间?_C#_Security_Content Management System_Signing_Pkcs#7 - Fatal编程技术网

C# 是否向PKCS7签名CMS添加签名时间?

C# 是否向PKCS7签名CMS添加签名时间?,c#,security,content-management-system,signing,pkcs#7,C#,Security,Content Management System,Signing,Pkcs#7,我正在尝试将“签名时间”属性添加到使用SignedCMS签名的文件中 private byte[] signFile(byte[] fileContent, X509Certificate2 verificationCert) { ContentInfo contentInfo = new ContentInfo(fileContent); SignedCms signedCMS = new SignedCms(contentInfo); CmsSigner cmsSign

我正在尝试将“签名时间”属性添加到使用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;
}
编码时引发错误:

CryptographicException: The object identifier is poorly formatted. 
有没有关于如何正确增加签名时间的想法?我想我可能必须将签名时间转换为ASN.1编码的对象,并将其添加到
cryptoAtty
的值中。如何将日期/时间转换为ASN.1编码的对象

那很容易

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