By Date: <-- -->
By Thread: <-- -->

How to verify a signed PDF with self-sign mode



Dear itext support,
After signing a PDF with self-sign mode, the digital signature was working properly with Adobe PDF Reader, but the PDF file could not verify with my code ( The code got from "How to sign PDF with itext"). When i made a change a PFD file, the verify program always notify that "PDF was not changed". Please help me sovle the problem. Here is the java code:
 
CertificateFactory cf = CertificateFactory.getInstance("X509");
   Collection col = cf.generateCertificates(new FileInputStream("export.cer"));
   KeyStore kall = KeyStore.getInstance(KeyStore.getDefaultType());
   kall.load(null, null);
   for (Iterator it = col.iterator(); it.hasNext();) {
        X509Certificate cert = (X509Certificate)it.next();
        kall.setCertificateEntry(cert.getSerialNumber().toString(Character.MAX_RADIX), cert);
   }
   PdfReader reader = new PdfReader("signed.pdf");
   AcroFields af = reader.getAcroFields();
   ArrayList names = af.getSignatureNames();
   for (int k = 0; k < names.size(); ++k) {
       String name = (String)names.get(k);
       System.out.println("Signature name: " + name);
       System.out.println("Signature covers whole document: " + af.signatureCoversWholeDocument(name));
       PdfPKCS7 pk = af.verifySignature(name);
       Calendar cal = pk.getSignDate();
       Certificate pkc[] = pk.getCertificates();
       System.out.println("Subject: " + PdfPKCS7.getSubjectFields(pk.getSigningCertificate()));
       System.out.println("Document modified: " + !pk.verify());
       Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal);
       if (fails == null)
           System.out.println("Certificates verified against the KeyStore");
       else
           System.out.println("Certificate failed: " + fails[1]);
 
Thanks you very much for your help,
Tuan 

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com