将签名时间添加到PKCS7已签名CMS吗?

问题描述 投票:6回答:2

我正在尝试将签名时间属性添加到使用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编码的对象?

c# security content-management-system signing pkcs#7
2个回答
11
投票

“替代文字”

很简单。

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

0
投票

我需要在签名中添加两个属性:signeddocument name

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.