Print Page | Close Window

Problems with DecryptFile Function

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1296
Printed Date: 05 May 24 at 7:41AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Problems with DecryptFile Function
Posted By: Shotgun Tom
Subject: Problems with DecryptFile Function
Date Posted: 19 Dec 09 at 8:13PM
I have spent the last two days trying to implement a decrypt file routine using, primarily, the QuickPDF DecryptFile function. 
 
The function looks like it works in that it returns a success code and actually writes the file... but there is no PDF reader on the planet that will open the file.  I thought for sure it must something I was doing.  I tried securing several different files... some with just a user password some with user and owner passwords... different levels of encryption.  I set the security in Adobe Pro 9.2.
 
Then I tried using Debenu's QuickPDF Tools.  Lo and behold, the same thing.  It writes the file but I can't open it in any PDF Reader... not Adobe, Acrobat, Fox-It, PCX View... they all give the same error.  The file is corrupted.  I assume that Debenu is using the DecryptFile routine in 7.17 which is what I've been dealing with.
 
Anyone else run into this problem?  Is this a known issue?
 
Tom



Replies:
Posted By: Michel_K17
Date Posted: 19 Dec 09 at 11:16PM
Actually, I have been using this function (successfully) for the last 4 years. Here is my VB code.

Note: make sure you use the "Owner"  password. It will definitely not work with the "User" password.

I hope it helps.

'---------------------------------------------------------------------------------------
' Procedure : PDF_Decrypt_File
' DateTime  : 11/26/2005 10:41
' Author    : Michel_K17
' Purpose   : This function will take an encrypted/locked PDF, and save it unencrypted.
'---------------------------------------------------------------------------------------
'
Private Function PDF_Decrypt_File(MyFile As String, pwd As String) As Boolean
   
    ' Trap Errors
    On Error GoTo Error_Handler
      
    ' Remove the Extension
    If Right$(MyFile, 4) = PDF Then MyFile = Left$(MyFile, Len(MyFile) - 4)
   
    ' Rename the file to process to an intermediate file
    Name MyFile & PDF As MyFile & "_D4W" & PDF
   
    ' Decrypt it
    rtn = oPDF.DecryptFile(MyFile & "_D4W" & PDF, MyFile & PDF, Decrypt(pwd, fUnicodeUser))
    If rtn = 1 Then PDF_Decrypt_File = True
   
    ' Delete the intermediate file
    Kill MyFile & "_D4W" & PDF

    Exit Function
   
Error_Handler:
    ' An unexpected error occured. Log it. (MUST have this line first, or the Err object gets reset).
    olog.LogError False, Err.Number, Err.Description, Err.LastDllError, "PDF_Decrypt_File"
   
End Function


-------------
Michel


Posted By: Shotgun Tom
Date Posted: 20 Dec 09 at 2:03AM
Hi Michel:
 
Thank you for your reply.  I will try this code.
 
However, many, many files are encrypted only with a User Password.  In other words, there are no permission's encryption, just a password for the User.  If I can't use the User password, how can I decrypt those successfully?
 
Tom
 
 BTW, I'm talking about permanently decrypting... that is... re-saving the file with no passwords, no security.


Posted By: Ingo
Date Posted: 20 Dec 09 at 12:03PM
Hi Tom!

We're talking about main and user passwords.
The user password is the one you have to insert while opening the pdf in a reader.
The main password the user won't see ... it's only to make the pdf-settings a little bit saver.
It's not possible to set only a user password. If the creator of a pdf determines a user- and not a main password the user password will be the main password, too.
There's no problem to analyze the structure of a pdf if there are user- and/or main-passwords.
If you want to decrypt AND SAVE a pdf which has a main- and a user-password it's okay to insert only the main-password.
If there's a user-password you can't do things like previews and textextractions without the user password... and i think that's good ;-)
This behavior doesn't belong only to the QuickPDF-sdk... that's normal for all libraries.

Cheers, Ingo

BTW: To all readers and writers here...
Merry Christmas and a Happy New Year 2010!




Posted By: Shotgun Tom
Date Posted: 20 Dec 09 at 2:52PM
Hi Ingo (and Michel):
 
Thank you for the reply, Ingo.  Just to let you guy's know... I finally went to bed and slept for a few hours.  Woke up and found out what I was doing wrong.  It had to do with having the document open in a viewer in the same program I was working on.  Sometimes sleep helps your brain Wacko
 
A very Merry Christmas and Happy New Year to you as well.  Enjoy the holidays!
 
Tom



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk