Quantcast

Error validating signed pdf with external sign

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Error validating signed pdf with external sign

jmheras

Hello ,

I've to sign with an external sgnature. When i open de PDF and validate it, I get an error message that says something like

document has been modified since sign was applied

 

The structure of code is:

- calc the hash

- send it to the external service

- get the external signature

- put it to de dic

 

Can you tell me what is wrong? or where to find the error?

 

thanks in advance,

Josep Maria

 

The code:

       PdfReader reader = new PdfReader(IN_FILE);

            FileStream fout = new FileStream(OUT_FILE, FileMode.Create);

 

            PdfStamper stp = PdfStamper.CreateSignature(reader, fout, '\0');

            DateTime cal = DateTime.Now;

 

            PdfSignatureAppearance sap;

            sap = stp.SignatureAppearance;

            sap.SetVisibleSignature(new Rectangle(100, 100, 300, 200), 1, "Signar");

 

           // sap.Layer2Text = ("Prova de firma.\n\nDate: ");

            //sap.Layer2Text = ("");

            PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKMS, PdfName.ADBE_PKCS7_DETACHED);

            dic.Put(PdfName.TYPE, PdfName.SIG);

            dic.Put(PdfName.M, new PdfDate(cal));

 

            sap.CryptoDictionary = (dic);

           // sap.Acro6Layers = (true);

            int contentEstimated = 15000;

            Dictionary<PdfName, int> exc = new Dictionary<PdfName, int>();

            PdfName contingut = new PdfName("");

            exc.Add(PdfName.CONTENTS, (contentEstimated * 2 + 2));

            sap.PreClose(exc);

 

            IDigest messageDigest = DigestUtilities.GetDigest("SHA1");

            Stream data = sap.GetRangeStream();

 

            // calc the hash

            byte[] buf = new byte[8192];

            int n1;

            while ((n1 = data.Read(buf, 0, buf.Length)) > 0)

            {

                messageDigest.BlockUpdate(buf, 0, n1);

            }

 

            byte[] hash = new byte[messageDigest.GetDigestSize()];

            messageDigest.DoFinal(hash, 0);

            // write hash to sent it to the extenal sign util

            System.IO.File.WriteAllText("C:/Reg/hash_ToBase64.txt", Convert.ToBase64String(hash));

            String shash = Convert.ToBase64String(hash);

            // extenal sign util process hash

            executeExe(shash);

            // get PKCS#7

            String spk7 = System.IO.File.ReadAllText("C:/tmp/Envelope.txt");

            byte[] bpk7 = Convert.FromBase64String(spk7);

 

            // put the PKCS#7 to disc.

            PdfDictionary updates = new PdfDictionary();

            byte[] out1 = new byte[contentEstimated];

            System.Array.Copy(bpk7, 0, out1, 0, bpk7.Length);

            updates.Put(PdfName.CONTENTS, new PdfString(out1).SetHexWriting(true));

            sap.Close(updates);

 

Le informamos que los datos personales de esta comunicación, están incorporados en un fichero bajo nuestra responsabilidad, para el tratamiento de datos de carácter personal, con la finalidad de mantenerle informado sobre los servicios que ofrece Adhoc Synectic Systems, S.A.Vd., como interesado directo, tiene derecho de acceso, rectificación, cancelación y oposición al tratamiento de la información que le concierne y autoriza a que pase a formar parte del fichero, ante el cual puede ejercer sus derechos, y recibir información y publicidad de productos y servicios de Adhoc Synectic Systems, S.A.Los derechos precitados podrán hacerse efectivos ante Adhoc Synectic Systems, S.A., Paseo Urrutia, 97, Local, 08042 - Barcelona, en el teléfono 93.276.83.40 o enviando un correo electrónico a [hidden email].(Ley Orgánica 15/1999 de 13 de Diciembre de Protección de Datos de Carácter Personal). Este mensaje de correo electrónico está dirigido exclusivamente al destinatario o destinatarios indicados en el mismo. La información en él contenida puede ser confidencial y/o privada por lo que está totalmente prohibida su difusión o reproducción. Si usted no es el destinatario de este mensaje, por favor devuélvalo inmediatamente a la dirección de envío y destrúyalo.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
mkl
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error validating signed pdf with external sign

mkl
Josep Maria,
jmheras wrote
I've to sign with an external sgnature. When i open de PDF and validate it, I get an error message that says something like
document has been modified since sign was applied
Please also supply a sample document signed by your code.

Regards,   Michael
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Error validating signed pdf with external sign

jmheras
Hi,

Here there is a sample result.

thankstest.signat.pdf
Loading...