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?