Hi,

I reviewed the forum answers and generated  a code as below. But the signed
pdf gives an error while verification.Please show me what is wrong on that.
I enclosed the out.pdf also..

ps: I have got the certificate after signing so i used that code sample
getting from forum answers.

Regards,


Here is the sample code:


*
            // reader and stamper
            PdfReader reader = new PdfReader(src);
            FileStream fout = new FileStream(dest, FileMode.Create);
            PdfStamper stp = PdfStamper.CreateSignature(reader, fout, '\0');
            byte[] hash = new byte[20];
            byte[] pk = new byte[128];

            PdfSignatureAppearance sap = stp.SignatureAppearance;


            sap.SignDate = DateTime.Now.Date;

            sap.SetExternalDigest(pk, hash, "RSA");

            sap.Reason = "Mobile Sign";
            sap.Location= "Anywhere";
            sap.Acro6Layers = true;

            sap.Layer2Text = "Mobile
Signing\n"+sap.Reason+"\n"+sap.Location;

            PdfSignature sigDic = new PdfSignature(PdfName.ADOBE_PPKMS,
PdfName.ADBE_PKCS7_DETACHED);
            sigDic.Put(PdfName.FT, PdfName.SIG);
            sigDic.Date = (new PdfDate(sap.SignDate));

            sigDic.Reason = "Mobile Signing";
            sigDic.Location = "Anywhere";
            sigDic.Contact = "ME";

            sap.SetVisibleSignature(new Rectangle(50, 10, 240, 70),
reader.NumberOfPages, "İmza");
            sap.Layer2Font = (FontFactory.GetFont(FontFactory.TIMES,
"windows-1254", 8));

            sap.CryptoDictionary = sigDic;

            sap.SetExternalDigest(pk, hash, "RSA");

            int csize = 4000;
            Dictionary<PdfName,int> exc = new Dictionary<PdfName,int>();
            exc.Add(PdfName.CONTENTS, csize * 2 + 2);
            sap.PreClose(exc);

            hash = getPdfHash(sap.RangeStream);

           MobileSignAPI msa= new MobileSignAPI();
            msa.Sign("053xxxxxxxx", "sign", encodeTo64(hash), "pdf
signing", 120);

 pk = base64DecodeToByteArr(msa.getSignatureValue));

            sap.SetExternalDigest(pk, hash, "RSA");

            byte[] outc = new byte[csize];
            PdfDictionary dic2 = new PdfDictionary();
            Array.Copy(pk, 0, outc, 0, pk.Length);
            dic2.Put(PdfName.CONTENTS, new
PdfString(outc).SetHexWriting(true));

            sap.Close(dic2);
            Console.Read();
*

Attachment: outpdf.pdf
Description: Adobe PDF document

------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
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