Hello everyone,

  I would like to add some restrictions on my pdf (user password, owner
password, read only mode...) and sign the result. I can sign it, I can encrypt
it, but I can't encrypt it then sign it, because when I do so, my pdf is only
signed, I loose my restrictions as the user password for example. Here is my
source code :

        // Encrypt it
        PdfReader reader = new PdfReader("guide.pdf");
        FileOutputStream fout = new FileOutputStream("encrypted.pdf");
        PdfEncryptor.encrypt(reader,fout,"user".getBytes(),     
"owner".getBytes(),0,true);

        // Sign it
        KeyStore ks = KeyStore.getInstance("pkcs12");
        ks.load(new FileInputStream("JohnSmith.pfx"), "azerty".toCharArray());
        String alias = (String) ks.aliases().nextElement();
        PrivateKey key = (PrivateKey) ks.getKey(alias, "azerty".toCharArray());
        Certificate[] chain = ks.getCertificateChain(alias);
        fout = new FileOutputStream("signednEncrypted.pdf");
        reader = new PdfReader("encrypted.pdf","owner".getBytes());
        PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
        PdfSignatureAppearance sap = stp.getSignatureAppearance();
        sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
        sap.setReason("I'm the author");
        sap.setLocation("Lisbon");
        stp.close();

Thanking you in advance.

John




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to