PdfFileSignature does not work with user password set by PdfFileSecurity

Hi,

I don't know if this is the expected behaviour, so please correct me if I'm wrong with expecting the following to work:

We want to encrypt a PDF and supply both user and owner password. Afterwards the PDF shall be signed. This works as long as I omit the user password (=set it to null). As soon as I specify a user password, the bookmarks get screwed up and the signature check of Acrobat fails complaining about an invalid attribute.

Code:

String inFile = "docobfuscated.pdf";
String outFile = "docobfuscated.out.pdf";
String outFile2 = "docobfuscated.out2.pdf";
PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile);
int priv=0;
priv|=PdfPrivilege.Copy;
priv|=PdfPrivilege.ScreenReaders;
priv|=PdfPrivilege.DegradedPrinting;
priv|=PdfPrivilege.Print;
fileSecurity.encryptFile("userpassword", "testpassword", priv, true);

PdfFileSignature pFileSignature = new PdfFileSignature();
Signature sgn = new Signature();
sgn.setRect(new java.awt.Rectangle(10, 10, 70, 70));
pFileSignature.bindPdf(outFile);
pFileSignature.setCertificateFile("test.pfx");
pFileSignature.setMultiSignature(true);
pFileSignature.setSignModel(PdfFileSignature.SELF);
pFileSignature.setPageNumber(1);
pFileSignature.setPassword("xxxxxxxxx");
pFileSignature.setSignature(sgn);
pFileSignature.setKeyStoreType("pkcs12");
pFileSignature.setCertificationLevel(PdfFileSignature.CERTIFIED_NO_CHANGES_ALLOWED);
pFileSignature.save(outFile2);

I'll attach the sample files (you'll need to add your own certificate and change the password accordingly).

Regards,
Mathias

Hi Mathias,

Please share the test.pfx file with us as well for complete testing of the issue using your particular scenario.

Regards,

Hi Shazad,

unless you suspect that our certificate is the cause of the problem, I would avoid supplying the certificate in question to an outside party. I suggest that you build your own certificate following the Adobe instructions that can be found at

http://help.adobe.com/en_US/Reader/8.0/help.html?content=WS58a04a822e3e50102bd615109794195ff-7d92.html

Regards,
Mathias

Hi Mathias,

I have reproduced this problem at my end and logged it as PDFKITJAVA-32412 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,