Hi, I have made a test to sign a pdf wih itext: the sample at http://itextpdf.sourceforge.net/howtosign.html#howtosign seems to work fine but when I open the signed PDF with Acrobat 8.1 (not the reader) I can see an error when of conformance to PDF/SigQ
I have linked error dialog box and the signed pdf
thanks in advance for your help
here the code :
KeyStore ks;
ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream(fileKey), fileKeyPassword.toCharArray());
String alias = (String) ks.aliases().nextElement();
PrivateKey key;
key = (PrivateKey) ks.getKey(alias, fileKeyPassword.toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);
File fileToSign = new File(fname);
PdfReader pdfReader = new PdfReader(fileToSign.getAbsolutePath());
FileOutputStream outputFile = new FileOutputStream(fileToSign
.getParent()
+ File.separator + fileToSign.getName() + "_signed2.pdf");
// Creation du tampon de signature
PdfStamper pdfStamper;
pdfStamper = PdfStamper.createSignature(pdfReader, outputFile, '\0');
PdfSignatureAppearance sap = pdfStamper.getSignatureAppearance();
sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
sap.setReason("I'm the author");
sap.setLocation("France");
//sap.setVisibleSignature(new Rectangle(10, 10, 50, 30), 1, null);
sap.setExternalDigest(new byte[512], new byte[20], "RSA");
sap.preClose();
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
byte buf[] = new byte[8192];
int n;
InputStream inp = sap.getRangeStream();
while ((n = inp.read(buf)) > 0)
{
messageDigest.update(buf, 0 , n);
}
byte hash[] = messageDigest.digest();
PdfSigGenericPKCS sg = sap.getSigStandard();
PdfLiteral slit = (PdfLiteral)sg.get(PdfName.CONTENTS);
byte[] outc = new byte[(slit.getPosLength() - 2) / 2 ];
PdfPKCS7 sig = sg.getSigner();
Signature sign = Signature.getInstance("SHA1withRSA");
sign.initSign(key);
sign.update(hash);
sig.setExternalDigest(sign.sign(), hash, "RSA");
PdfDictionary dic = new PdfDictionary();
byte[] ssig = sig.getEncodedPKCS7();
System.arraycopy(ssig, 0, outc, 0, ssig.length);
dic.put(PdfName.CONTENTS, new PdfString(outc).setHexWriting(true));
sap.close(dic);
<<attachment: Error_control_signPDF.gif>>
original.pdf_signed2.pdf
Description: Adobe PDF document
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
