Hi, i am a German student and i would like to create an application wich sign
PDF-Documents with external signatures.
Ok, the following things i want to do:
1) get the signature + certificate from Smard-Card(REINER) with OCF
//the certificate
X509Certificate tSigningCertificate =
Gov2SmartCardHelper.getInstance().getSignatureX509Certificate();
//sign the file and get the hash bytes with SHA1withRSA algorithm
byte [] tBs =
Gov2SmartCardHelper.getInstance().sign(IOHelper.getBytesFromFile(tUnsignedFile));
Certificate[] tCertificates = new Certificate[]{tSigningCertificate};
2) Add signature + certificate to the PDF-Document
Calendar tCalendar = Calendar.getInstance();
PdfStamper tStamper =
PdfStamper.createSignature(tReader,tOutStream,'\0');
PdfSignatureAppearance tSignatureAppearance =
tStamper.getSignatureAppearance();
tSignatureAppearance.setLayer2Text("signature.\n\nDate: today");
tSignatureAppearance.setVisibleSignature(new
com.lowagie.text.Rectangle(100, 180, 200, 200), 1, null);
tSignatureAppearance.setSignDate(tCalendar);
//Add the certificate
tSignatureAppearance.setCrypto(null,tCertificates , null,
PdfSignatureAppearance.SELF_SIGNED);
tSignatureAppearance.setReason("AI-Signing reason");
tSignatureAppearance.setLocation("Far far away");
//i need this, otherwise i get a NullPointerException in the next line. The
stacktrace, see end of message.
tSignatureAppearance.setExternalDigest(new byte[128], null, "RSA");
tSignatureAppearance.preClose();
//add signature
PdfPKCS7 tSig = tSignatureAppearance.getSigStandard().getSigner();
tSig.setExternalDigest(tBs, null, "RSA");
PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.CONTENTS, new
PdfString(tSig.getEncodedPKCS1()).setHexWriting(true));
tSignatureAppearance.close(dic);
Its work but my Acrobat Reader says: Signature is INVALID
- The Document hast been altered or Corrupt since th Signature was applied.
- The Signer's Identety is Unknown becous it has not been included in your
list of Trusted Identities and none of its parent Certificates are Trusted
Identities.
But i can see the certificate in Adobe-Reader!
Sorry i am not a signing specialist but i think i have a working knowledge
of signing.
I would be very happy if anyone can help me or give me any tips.
Greetings
Fionn
java.lang.NullPointerException
at com.lowagie.text.pdf.PdfPKCS7.getEncodedPKCS1(Unknown Source)
at com.lowagie.text.pdf.PdfSigGenericPKCS.setSignInfo(Unknown Source)
at com.lowagie.text.pdf.PdfSignatureAppearance.preClose(Unknown Source)
at com.lowagie.text.pdf.PdfSignatureAppearance.preClose(Unknown Source)
at PDFSigner.sign(PDFSigner.java:103)
tSignatureAppearance.close(dic);
--
View this message in context:
http://www.nabble.com/Signing-PDF-Document-with-external-Certificate-and-Signature-%28Signature-is-INVALID%29-tf4639103.html#a13249851
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
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/