C# 是否向PKCS7签名CMS添加签名时间?
我正在尝试将“签名时间”属性添加到使用SignedCMS签名的文件中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
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());