【问题标题】:Add Signing Time to PKCS7 Signed CMS?将签名时间添加到 PKCS7 签名 CMS?
【发布时间】:2010-08-18 14:31:23
【问题描述】:

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


    【解决方案1】:

    这很容易。

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

    【讨论】:

      猜你喜欢
      • 2020-05-06
      • 2016-11-30
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 2017-12-21
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多