2010-08-18 3 views
5

J'essaye d'ajouter l'attribut de temps de signature à un dossier que je signe en utilisant SignedCMS.Ajouter l'heure de signature à PKCS7 CMS signé?

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; 
} 

Erreur jeté sur Encode:

CryptographicException: The object identifier is poorly formatted. 

Toutes les idées sur la façon d'ajouter correctement le temps de signature? Je pense que je devrais convertir l'heure de signature en objet codé ASN.1 et l'ajouter aux valeurs de cryptoAtty. Comment convertir une date/heure en un objet ASN.1 Encoded?

Répondre

10

alt text

Eh bien, ce fut facile.

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