2010-08-18 9 views
5

Estoy tratando de agregar el atributo de tiempo de firma a un archivo que estoy firmando usando SignedCMS.Agregar tiempo de firma a PKCS7 ¿CMS firmado?

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 tirado en Codificar:

CryptographicException: The object identifier is poorly formatted. 

Cualquier ideas sobre cómo agregar correctamente el tiempo de la firma? Creo que debo convertir el tiempo de firma en un objeto codificado en ASN.1 y agregarlo a los valores de cryptoAtty. ¿Cómo se convertiría la fecha/hora a un objeto codificado ASN.1?

Respuesta

10

alt text

Bueno, eso fue fácil.

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