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,
张健
------------------------------------------------------------------------------
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

Reply via email to