Hi Jian,
from a first look at the code sample I would assume the difference is the
missing padding in version 2.
But I'm not quite sure how a missing padding wouldn't cause a BER decoding
error ...
I always a good idea to post sample PDF. Many guys on the list have their
favourite tools to spy into the PDF bytes and get results more easily than
trying to interpret a code snippet.
Greetings
Andreas
----- original Nachricht --------
Betreff: Re: [iText-questions] Another invalid signature thread
Gesendet: Mi, 27. Okt 2010
Von: jian zhang
Hi,my code is:
InputStream rs = appearance.getRangeStream(); byte[]
content = streamToByteArray(rs, 1024); rs.close();
byte[] signedHashValue1 = server.sha1_rsa(content);
//===sha1 then rsa========= byte[] hash =
server.sha1(content); byte[] signedHashValue2=server.rsa(hash);
//=========================
// add signed hash value into pdf PdfPKCS7 sig =
appearance.getSigStandard().getSigner();
sig.setExternalDigest(signedHashValue2, hash, "RSA"); PdfDictionary
dic = new PdfDictionary(); dic.put(PdfName.CONTENTS,
new PdfString(sig.getEncodedPKCS1()).setHexWriting(true));
appearance.close(dic);
when I use signedHashValue1 , it's ok , I can get a valid signature in pdf;but
when I use signedHashValue2, get an error , says"Error encountered while BER
decoding".
public byte[] sha1(byte[] content) { MessageDigest md;
md = MessageDigest.getInstance("SHA-1");
return md.digest(content); }
public byte[] rsa(byte[] hash) { Signature
signature = Signature.getInstance("NONEwithRSA");
signature.initSign(this.privateKey); signature.update(hash);
return signature.sign(); }
public byte[] sha1_rsa(byte[] content) {
Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign(this.privateKey);
signature.update(content); return signature.sign();
}
If I use "SHA1withRSA" ,I will get an invalid signature says "document has been
modified"
--
Best Regards£¬
ÕŽ¡
--- original Nachricht Ende ----
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
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