arnabroy,

arnabroy wrote
> same error file corrupted
> please help
> 
> STEP1: creating the hash of the pdf file in the server

This is wrong. In your original attempt you started by creating a PdfStamper
and calculating the hash of the range stream:

>     PdfStamper stamper = PdfStamper.CreateSignature(reader, fout, '\0');
>     PdfSignatureAppearance appearance = stamper.SignatureAppearance;
>     ...
>     Stream data = appearance.GetRangeStream();
>     ...
>     byte[] hash = new byte[messageDigest.GetDigestSize()];
>     messageDigest.DoFinal(hash, 0);

This was correct (or might be, I'm normally dealing with Java and don't know
the .Net IDigest contract): You have to sign this very document hash and
then insert the CMS signature into this very PdfStampter because the signed
data is more than the bytes of the original PDF file, and even they often
are somewhat rearranged.

For some backgrounds read this Security Stack Exchange answer:
http://security.stackexchange.com/a/35131/16096

Your original attempt failed thereafter by completely messing up the
signature container creation.

The final insertion of the signature container was correct, too

>     byte[] paddedSig = new byte[8192];
>     Array.Copy(encodedSig, 0, paddedSig, 0, encodedSig.Length);
>     PdfDictionary dic2 = new PdfDictionary();
>     dic2.Put(PdfName.CONTENTS, new
> PdfString(paddedSig).SetHexWriting(true));
>     sap.Close(dic2);

You merely have to correctly create a good detached CMS signature of that
signature inbetween these code fragments.

As mentioned before I generally deal with Java, not C# or JavaScript, and,
therefore, cannot tell how best to create that signature in your
environment.

Regards,   Michael



--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Sign-and-PDF-with-SmartCard-and-web-browser-only-tp4319344p4660343.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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

Reply via email to