Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
problems with encrypted PDFs |
Post Reply |
Author | |
ukobsa
Senior Member Joined: 29 May 06 Location: Germany Status: Offline Points: 115 |
Post Options
Thanks(0)
Posted: 08 Nov 06 at 9:59AM |
Hi,
I had some problems with a PDF doc that was created using PDF XChange 3: I started with a simple txt file containing 'hello World'. Then I printed it to PDF with PDF XChange 3's virtual printer using the following options: - use PDF security - userpassword: test - no owner password - 40 Bit encryption - disabled all four modification options This pdf opens fine with Acrobat Reader asking for password but cannot be opened and unencrypted by QuickPDF as it says that 'test' is not a valid password. After some debugging I found a solution for it: TPDFDocument.GenerateEncryptionKeys has a line : if not (ppCanAddNotes in FPermissions) then PermKey := PermKey and $FFFFFFDC; if FEncryptionStrength <> esStd then begin ... Remove line 'if FEncryptionStrength <> esStd then' and it works. Why: encrypting the user password includes the permissions for the file. And when PDF XChange 3 creates the PDF it sets the permissions for 128 bit encryption to zero when using 40 bit encryption. So this way you can see an permission value of -3904 in the pdf source (which is also reflected on the encrypted user password). Now QuickPDF reads it and tries to unencrypt. So it encryptes the entered user password 'test' to compare it with the found value of the pdf source. But to do so QuickPDf says: 40 bit, ok so set all other bits of the permission key to 1 except But this results in a permissionkey value of -64. But the encrypted user password using -64 as permission key differs from the one using -3904 . So it says invalid password. Removing the suggested line sets all found permissions (if they are used or not) and so the password can be encrypted right. Your comments about this please ... (you should be able to create test docs using the trial version of PDF XChange 3 as I did. best regards, Uli Edited by ukobsa |
|
ukobsa
Senior Member Joined: 29 May 06 Location: Germany Status: Offline Points: 115 |
Post Options
Thanks(0)
|
Next problem with this pdf: print the same file but now with following options:
- PDF Spec: conform to 1.6 - use PDF security - no owner and no user password - 40 bit encryption This file can also be opened fine with Acrobat Reader but always says 0 pages with QuickPDF. This is caused be the fact that quickPDF cannot create the page dictionary. When you look at the PDF source you can see that the page object is not available as a plain object but contained in an object stream (which is encrypted according to the settings). So what happens when the file is loaded: TPDFDocument.ValidPDFSource reads Header and Trailer and then tries to build the pagetree. And here it fails as it cannot read the content. Internaly it had to read the page object from the object stream (which it tries to do right). But it cannot decode the stream as it seems always comes back with a data error. Here the reason is that the stream is still encrypted! During reading the page it looks if it has to unencrypt the stream. And as the internal password is blank ('') it doesn't encrypt. So why is it ''? If you look at TPDFDocument.SetPassword you can see that a call to SetPassword with a valid password (alos the blank one) doesn't leave the internal password blank but set it at least to '!'. And this is the solution: set the internal password to '!' before building the pages dictionary. function TPDFDocument.ValidPDFSource: Boolean; var LinData: string; OP: Integer; LinObj: string; LinGen: string; LinIO: TPDFIndObj; LinDict: TPDFDictionary; TestObj: TPDFObject; begin ... Result := True; if Assigned(FPageTree) then FPageTree.Free; // UKO 09.11.2006 // Password needs to be set here to ensure that encrypted Object streams // containing page objects can be decrypted properly. Password := ''; FPageTree := TPDFPageTree.Create(GetPagesDict, FImages); btw: LoadFromStream also set the password to '' (-> internal password to '!'), but only after loading the PDF source which is to late for encrypted object streams. in general: Current QuickPDf will fail to load a PDF whenever it contained page objects in an object stream and the PDF is encrypted. The above source change should fix this. HTH, Uli |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Uli!
Great!!! If you dig into something you dig to the bottom ;-) Good work!!! Best regards, Ingo |
|
HJBrown
Beginner Joined: 26 Jun 06 Location: Cape Verde Status: Offline Points: 2 |
Post Options
Thanks(0)
|
Has this issue with UNENCRYPT been addressed in the latest release? Thanks for your support.
|
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi!
Since version 5.15 it's included... Best regards, Ingo |
|
ukobsa
Senior Member Joined: 29 May 06 Location: Germany Status: Offline Points: 115 |
Post Options
Thanks(0)
|
I fear it's not included: I just have looked on the source (5.21) and only the second change is included as a comment. Maybe Marian has found another solution so that my original code is obsolete.
Ulrich |
|
HJBrown
Beginner Joined: 26 Jun 06 Location: Cape Verde Status: Offline Points: 2 |
Post Options
Thanks(0)
|
I actually tested this function with a PDF that is at 1.6, is encrypted with 40bit RC and the Unencrypt did not seem to work.
|
|
mark
Beginner Joined: 27 Feb 07 Location: United States Status: Offline Points: 10 |
Post Options
Thanks(0)
|
I am having a problem with decryption as well, though I don't know if it's the same problem or different.
My encryption is performed by QuickPDF, at 128bits, with both an owner and user password. When the saved file is opened in Acrobat Reader (6.0), it accepts both passwords and properly handles the document, along with the permissions I set from within QuickPDF.... so it appears there is no problem with encryption. When I decrypt from within QuickPDF I don't get an error back -- the return value is proper according to owner or user password as provided. There are two glaring problems that I can see though. My document consists of a background image, and 68 form fields. When decrypted by QuickPDF, it still agrees that there are 68 form fields. For each of them, it seems to also know the proper bounds. (I haven't checked to see if these things would be seen if I did not decrypt the document.) Problem 1: the background graphic will not display from QuickPDF's rendering anymore. Problem 2: the field titles are all scrambled. I haven't checked Acrobat Pro to make sure it can interpret them correctly still, but since Reader displays the background graphic properly still, I suspect it may. |
|
marian_pascalau
Debenu Quick PDF Library Expert Joined: 28 Mar 06 Location: Germany Status: Offline Points: 278 |
Post Options
Thanks(0)
|
Guys, in 5.22 I have solved a huge bug with the decryption of PageTree dictionary. Because of a strange caching of Page references overwritten with some access optimization it was impossible to decrypt dictionaries although the document had all the information needed. Can you please test the last version in an attemt to confirm my sollution.
Thank you, Marian
|
|
marian_pascalau
Debenu Quick PDF Library Expert Joined: 28 Mar 06 Location: Germany Status: Offline Points: 278 |
Post Options
Thanks(0)
|
HJBrown, please understand that PDF1.6 specific dictionaries are not implemented.
|
|
mark
Beginner Joined: 27 Feb 07 Location: United States Status: Offline Points: 10 |
Post Options
Thanks(0)
|
Hi Marian,
I don't know what a dictionary is, as it relates to a PDF file. From what I posted, do you think this may be the cause of what I'm seeing? If you can send me a DLL binary, I will test what you have. The binary I currently have is 5.22. (I'm not sure from your post if you mean you have something more recent than what is in the public download page.) |
|
ukobsa
Senior Member Joined: 29 May 06 Location: Germany Status: Offline Points: 115 |
Post Options
Thanks(0)
|
Marian,
can yo include my changes to the next version? Maybe it solves the problem hjbrown has. Urich |
|
marian_pascalau
Debenu Quick PDF Library Expert Joined: 28 Mar 06 Location: Germany Status: Offline Points: 278 |
Post Options
Thanks(0)
|
Hi there,
I can confirm that in the 5.22 version there was a bug affecting document with normal PDF encryption :-(
|
|
ditte
Beginner Joined: 18 Apr 07 Location: Germany Status: Offline Points: 10 |
Post Options
Thanks(0)
|
Hi,
sorry that I churn up the old thread. I´ve also this problem (or a other??). I get a invoise of (strato - is a provider). I read with acrobat a put a copy in my system. Now I like to read it with the gdpicturepro (isedquichpdf) but the screen will be white??? I´m using the isedquickpdf(5.22.0.119) inside the gdpicturepro (3.03.0001) Have somebody a solution for me. Regards Dittmar |
|
marian_pascalau
Debenu Quick PDF Library Expert Joined: 28 Mar 06 Location: Germany Status: Offline Points: 278 |
Post Options
Thanks(0)
|
ditte,
for a propper answer you should send your file to support(at)quickpdf.org
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store