Hi,
thanks for the quick responses
mkl wrote:
>
> ...
> IF that method is called, it requires the private key object. But there
> are a number of examples on the howtosign page you referred to which do
> not use that method.
> ...
> In this case the private key essentially is used to create some signature
> dictionary entries. The public certificate would have sufficed, though.
>
Following the "Signing a PDF with a smart card" example from the current
"iText in Action" book I tried to use an external digest without the private
key:
sap.setCrypto(null, chain, null, PdfSignatureAppearance.SELF_SIGNED);
sap.setExternalDigest(new byte[128], null, key.getAlgorithm());
sap.preClose();
byte[] content = streamToByteArray(sap.getRangeStream());
PdfPKCS7 sig = sap.getSigStandard().getSigner();
Signature sign = Signature.getInstance("SHA1with" + key.getAlgorithm());
sign.initSign(key);
sign.update(content);
sig.setExternalDigest(sign.sign(), null, key.getAlgorithm());
PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.CONTENTS, new
PdfString(sig.getEncodedPKCS1()).setHexWriting(true));
sap.close(dic);
And this works quite fine (at least Adobe Reader is able to verify the
signature, haven't tried to verify with iText yet). However hashing the
content with a MessageDigest and signing the hash as in the book's example
instead of signing the content directly results in an invalid signature...
Best regards,
Daniel
--
View this message in context:
http://old.nabble.com/How-to-sign-examples-tp26886381p26887926.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
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/