Each time the program is run a different /ID is generated. This is a PDF thing ad can't be changed.
Paulo ----- Original Message ----- From: "amarianoelaide" <[email protected]> To: <[email protected]> Sent: Tuesday, March 31, 2009 11:02 AM Subject: [iText-questions] Hash computation problem Hi all, just a question about the hash computation. With reference to this code: PdfReader pdfReader = new PdfReader("/home/amariano/Desktop/sample.pdf"); FileOutputStream PdfInMemory = new FileOutputStream("/home/amariano/Desktop/out.pdf"); PdfStamper pdfStamper = PdfStamper.createSignature(pdfReader, PdfInMemory, '\0'); PdfSignatureAppearance pdfSigApp = pdfStamper.getSignatureAppearance(); PdfSignature sigDic = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_DETACHED); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(new SimpleDateFormat("yyyyMMdd").parse("20090303").getTime()); sigDic.setDate(new PdfDate(cal)); sigDic.setReason("Pdf signature test"); sigDic.setLocation("Italy"); sigDic.setContact("Elaide S.r.l."); sigDic.setName("ACTestClient"); pdfSigApp.setCryptoDictionary(sigDic); pdfSigApp.setAcro6Layers(true); HashMap<Object, Object> exclusions = new HashMap<Object, Object>(); exclusions.put(PdfName.CONTENTS, new Integer(4000*2+2)); pdfSigApp.preClose(exclusions); byte[] hash = getHash(pdfSigApp); System.out.println(new BASE64Encoder().encode(hash)); where getHash is as following: public static byte[] getHash(PdfSignatureAppearance pdfSigApp) throws Exception { byte buf[] = new byte[8192]; int n; InputStream inp = pdfSigApp.getRangeStream(); MessageDigest messageDigest = MessageDigest.getInstance("SHA1"); while ((n = inp.read(buf)) > 0) { messageDigest.update(buf, 0, n); } byte hash[] = messageDigest.digest(); return hash; } if I run this code more than once I obtain different hash values. it's obvious that some "randomness" is introduced during successive hash computations. Is it possible to avoid it? And if yes how? If not, is it an IText peculiarity or is it a PDF hashing process issue? Hashing a normal file (text, binary, etc...) gives always the same hash value Thank you. Antonio Mariano ------------------------------------------------------------------------------ _______________________________________________ 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
