1

Hello how are you Well I tell you my problem. In my work they use digital signature to validate pdf files that are then delivered to those who apply (those who request do not belong to the company), so in the pdf must be signed with the data of the signer. The signature is being done with the adobe assistant, and using digital signed tokens installed on the computer. Well people who have to sign sign about 200 pdf per day. So I'm developing a desktop application in C sharp that will allow me to sign all the pdfs at one time, since with adobe they have to open the pdf, create a signature field, put the token key and just the signature appears , This multiplied by 100 or 200 according to the day. From what I was researching can be done. What I have so far is a button that opens a dialog that allows you to select all the pdfs to sign. Then another button that opens the windows certificate store to select the certificate to sign. But I can not create a field and insert the signature, asking beforehand the key of the token. //// with the method below I open the certificate store and select one to sign

private void btnExplorar_Click(object sender, EventArgs e)
{
    X509Store store= new X509Store(StoreName.My,StoreLocation.CurrentUser);


    store.Open(OpenFlags.ReadOnly);

    X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
    X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);

    X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Lista de Certificados digitales instalados en su equipo", "Seleccion el certificado con el que desea firmar", X509SelectionFlag.SingleSelection);
    //  X509Certificate2 certificadoElegido = scollection[0];

    if (scollection.Count > 0)
    {

      certificadoElegido = scollection[0];//certificadoElegido is a  class variable

}

With this method I scroll a listbox with the list of all the selected pdfs to sign and I try to create a field, but I do not know how to get that field to be created in the pdf and make the signature. I need of course that signature is later seen in the pdf so that the applicants know who signed it

private void button1_Click(object sender, EventArgs e)
{
    if (cLBoxListadePdf.CheckedItems.Count!=0) {
        string pdfAFirmar;
        int i;
        for (i=0;i<=cLBoxListadePdf.CheckedItems.Count-1;i++) {
            pdfAFirmar = cLBoxListadePdf.CheckedItems[i].ToString();

            PdfReader pdf = new PdfReader(pdfAFirmar);
            PdfStamper stamper = PdfStamper.CreateSignature(pdf,new FileStream("C:\\Users\...", FileMode.Create), '\0');
            PdfSignatureAppearance sap = stamper.SignatureAppearance;
            sap.Reason = "";
            //sap.Location=100;
            stamper.Close();
        }
    }
}

Any suggestions on how to complete this work is welcome. Sorry for my english i used the google translate.

2
  • For a comprehensive overview of signing with iText cf. the white paper Digital Signatures for PDF Documents; the C# versions of the Java samples can be found here.
    – mkl
    Mar 3, 2017 at 17:31
  • Also make sure that you use at least iText 5.4.x or your signatures will be invalid because of the proven insecurity of SHA-1 and the deprecation of the only signature types that were supported in older iText versions. Mar 3, 2017 at 18:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.