|
From: <php...@li...> - 2009-12-01 16:02:19
|
Hi all, I'm new in the java-bridge technologies and have to create a PHP script to generate and signed an PDF. My problem come from 'byte' data type. I try to find a solution in archives and FAQ but nothing works... My java source code ( from http://itextpdf.sourceforge.net/howtosign.html -> How to sign with a timestamp and OCSP in Java) has to be 'traduce' to PHP. For the rest of the page, I think I'm fine, but when i declare the buf[] and use the messageDigest.update on it, I got unexpected result... (that's why I have a System.out.print("n=" + n) for the debug ) java result: n=191n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=4525 php result: n=184n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=8192n=6260 Exception... (when i use a array of 'int' instead of 'byte') [java code] byte buf[] = new byte[8192]; int n; while ((n = data.read(buf)) > 0) { messageDigest.update(buf, 0, n); System.out.print("n=" + n); } byte hash[] = messageDigest.digest(); Calendar cal = Calendar.getInstance(); byte[] ocsp = null; if (chain.length >= 2) { String url = PdfPKCS7.getOCSPURL((X509Certificate)chain[0]); if (url != null && url.length() > 0) ocsp = new OcspClientBouncyCastle((X509Certificate)chain[0], (X509Certificate)chain[1], url).getEncoded(); } byte sh[] = sgn.getAuthenticatedAttributeBytes(hash, cal, ocsp); sgn.update(sh, 0, sh.length); byte[] encodedSig = sgn.getEncodedPKCS7(hash, cal, tsc, ocsp); if (contentEstimated + 2 < encodedSig.length) throw new Exception("Not enough space"); byte[] paddedSig = new byte[contentEstimated]; System.arraycopy(encodedSig, 0, paddedSig, 0, encodedSig.length); PdfDictionary dic2 = new PdfDictionary(); dic2.put(PdfName.CONTENTS, new PdfString(paddedSig).setHexWriting(true)); sap.close(dic2); If someone can help to 'traduce in php' this code or just explain my exactly how to produce a array[8192] of byte. Best regards Antoine _________________________________________________________________ Messenger à partir de votre boîte de réception ! Découvrez la foule d'atouts de Hotmail. http://www.microsoft.com/switzerland/windows/fr/windowslive/hotmail_bl1/hotmail_bl1.aspx |