Hi
.I need to ask one think that whether i can sign at client end in a web
application with itextsharp.The signature is on smart cad which is at client
end.If not,i am signing at client end and i am generating signature.Now i
want to put that signature on pdf using itextsharp.I tried following
code,But when i open pdf and click on signature it shows following errors:-
1."Error while verification(BER Encoding)
2.Non-empty content info is required
3.Error during signature verification
A little help will be appreciated.Hope for a quick and positve reply

 public static void SignHashed(byte[] pdf, string path,string
path1,byte[]pdf_sign)
    {
        PdfReader reader = new PdfReader(path);
        PdfStamper stp = PdfStamper.CreateSignature(reader, new
FileStream(path1, FileMode.Create), '\0');
        PdfSignatureAppearance sap = stp.SignatureAppearance;
        sap.SetVisibleSignature(new Rectangle(100, 100, 300, 200), 1, null);
        sap.SignDate = DateTime.Now;
        sap.SetExternalDigest(pdf_sign, pdf, "RSA");
        //sap.SetCrypto(null, chain, null, null);
        sap.Reason = "I like to sign";
        sap.Location = "Universe";
        sap.Acro6Layers = true;
        sap.Render =
PdfSignatureAppearance.SignatureRender.NameAndDescription;
        PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKMS,
PdfName.ADBE_PKCS7_SHA1);
        dic.Date = new PdfDate(sap.SignDate);
        dic.Name = "AshishD";
        if (sap.Reason != null)
            dic.Reason = sap.Reason;
        if (sap.Location != null)
            dic.Location = sap.Location;
        sap.CryptoDictionary = dic;
        int csize = 4000;
        Dictionary<PdfName, int> dic_ex = new Dictionary<PdfName, int>();
        dic_ex.Add(PdfName.CONTENTS, csize * 2 + 2);
        Hashtable dic_hasht = new Hashtable(dic_ex);
        sap.PreClose(dic_hasht);

        HashAlgorithm sha = new SHA1CryptoServiceProvider();

        Stream s = sap.RangeStream;
        int read = 0;
        byte[] buff = new byte[8192];
        while ((read = s.Read(buff, 0, 8192)) > 0)
        {
            sha.TransformBlock(buff, 0, read, buff, 0);
        }
        sha.TransformFinalBlock(buff, 0, 0);
        //byte[] pk = SignMsg(sha.Hash, card, false);

        byte[] outc = new byte[csize];

        PdfDictionary dic2 = new PdfDictionary();

        Array.Copy(pdf_sign, 0, outc, 0, pdf_sign.Length);

        dic2.Put(PdfName.CONTENTS, new PdfString(outc).SetHexWriting(true));
        sap.Close(dic2);
        reader.Close();
        stp.Reader.Close();
    }

-- 
Thanks and Regards,
Ashish Dhingra,
Software Engineer,
M-09467783146
God first everything else next
------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

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