Hi max,

could you please forward the signed PDF? 

Greetings
Andreas

----- original Nachricht --------

Betreff: Re: [iText-questions] Sign and PDF with SmartCard and web browser only
Gesendet: Mi, 08. Feb 2012
Von: madmax

Hi MichaelI looked a little dipper to what you were saying and begun looking 
closer to my “verify” method and  it dawned on  me that I 
had seen similar code from an example  of detached signature and using 
BouncyCastle (source: 
http://itextpdf.sourceforge.net/howtosign.html#signextdiccms
I rewrote the code to inject the signature as follows:
   private void signPdf(String path, String fileName, String digest, 
HttpServletRequest request) {HttpSession session = 
request.getSession();PdfStamper stamper;PdfSignatureAppearance 
appearance;stamper = (PdfStamper) session.getAttribute("stamper");appearance = 
stamper.getSignatureAppearance();byte[] hash = ((String) 
session.getAttribute("hash")).getBytes();log.info("signPdf with 
Digest(begin)...");try {//      String content = (String) 
session.getAttribute("hash");int csize = 15000;byte[] data = 
Base64.decodeBase64(digest.trim().getBytes());Security.addProvider(new 
BouncyCastleProvider());  CMSSignedData signedData = new CMSSignedData(data); 
byte[] pk = signedData.getEncoded();byte[] outc = new byte[csize];PdfDictionary 
dic2 = new PdfDictionary();System.arraycopy(pk, 0, outc, 0, 
pk.length);dic2.put(PdfName.CONTENTS, new 
PdfString(outc).setHexWriting(true));appearance.close(dic2);}catch (IOException 
e) {e.printStackTrace();}catch (DocumentException e) 
{e.printStackTrace();}catch (Exception e) 
{e.printStackTrace();}log.info("signPdf with Digest (end)...");}
I am almost there adobe is no longer crashing when I look at the signature, but 
when I try to verify it  says “the document has been altered or 
corrupted since the signature was applied” see attached  jpg. 

Is this related to a datetime stamp issue between the servlet reserving the 
space for the digest and the browser creating the signature a few second apart? 
 Do you know how I could fix resolve this

Thanks again,

max

2-8-2012_00-36-22.png
2-8-2012_00-35-18.png
2-8-2012_00-34-28.png
View this message in context: Re: Sign and PDF with SmartCard and web browser 
only
Sent from the iText - General mailing list archive at Nabble.com.


--- original Nachricht Ende ----
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
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