Hello,

i have tried to run the example with an external signature in Self Sign Mode, 
like described on: (http://itextpdf.sourceforge.net/howtosign.html#signextstd) 
see code below at the end of the mail.

The sign process works without errors, but if i open the signed PDF document 
with Acrobat reader 9.1.3

I get the error:

... SigDict / Contents illegal data

I don't know what i must change to remove the error. Can anyone give me a tip 
please?

By the way: i have tried also the example with an external hash and signature 
in Windows Certificate Mode
an that works fine.

Regards and thanks in advance

Manfred

The executed code:

KeyStore ks = KeyStore.getInstance("jks");
ks.load(new FileInputStream("c:\\.keystore"), "my_password".toCharArray());
String alias = (String)ks.aliases().nextElement();
PrivateKey key = (PrivateKey)ks.getKey(alias, "my_password".toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader("c:\\original.pdf");
FileOutputStream fout = new FileOutputStream("c:\\signed.pdf");
PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, chain, null, PdfSignatureAppearance.SELF_SIGNED);
sap.setReason("I'm the author");
sap.setLocation("Lisbon");
// comment next line to have an invisible signature
sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
sap.setExternalDigest(new byte[2048], null, "RSA");
sap.preClose();
PdfPKCS7 sig = sap.getSigStandard().getSigner();
Signature sign = Signature.getInstance("SHA1withRSA");
sign.initSign(key);
byte buf[] = new byte[8192];
int n;
java.io.InputStream inp = sap.getRangeStream();
while ((n = inp.read(buf)) > 0) {
sign.update(buf, 0, n);
}
sig.setExternalDigest(sign.sign(), null, "RSA");
PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.CONTENTS, new 
PdfString(sig.getEncodedPKCS1()).setHexWriting(true));
sap.close(dic);

 




------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to