Thanks Tilman!

I have tested your code & it works fine 😊

 

 

Best regards,

Hesham 

 

--------------------------------------------------------------------------------------------------

Included Message:

 

here's some code... I'm also adding it to our tests as some extra fun.

 

 

        PDEncryption encryption = doc.getEncryption();

        int revision = encryption.getRevision();

        if (revision < 5)

        {

            StandardSecurityHandler standardSecurityHandler = new 
StandardSecurityHandler();

            int keyLengthInBytes = encryption.getVersion() == 1 ? 5 : 

encryption.getLength() / 8;

            byte[] computedUserPassword = 
standardSecurityHandler.getUserPassword(

                    ownerpassword.getBytes(Charsets.ISO_8859_1),

                    encryption.getOwnerKey(),

                    revision,

                    keyLengthInBytes);

 

        }

 

You could also try to use incremental saving. But it is tricky (you need to set 
a "breadcrumb trail" to your updated element(s)) and buggy (if there is a 
signature and you don't sign yourself).

 

Tilman

 

Am 04.01.2018 um 08:26 schrieb Hesham Gneady:

> Thanks a lot Tilman .. I will try that 😊

> 

> 

> 

> Best regards,

> Hesham

> 

> ----------------------------------------------------------------------

> ----------------------------

> Included Message:

> 

> It is possible for older encryption (not AES256): get the source code and 
> have a look at StandardSecurityHandler.java. There is a segment where 
> "isOwnerPassword()" is called, and a bit later, "computedPassword"

> is calculated by calling getUserPassword(). I tried this by debugging with 
> out test files and yes I got the user password.

> 

> So you could do it by 1) get length, revision and owner key from the 
> PDEncryption object you get by calling document.getEncryption() 2) check that 
> revision is smaller then 5, and 3) call getUserPassword().

> 

> Tilman

> 

> Am 03.01.2018 um 09:29 schrieb Hesham Gneady:

>> Hello,

>> 

>>    

>> 

>> I have a PDF file that has an owner password & user password. I'd 

>> like to decrypt it using the owner password, make some modifications 

>> to it, then encrypt it back and save it. I did the first part 

>> successfully, but how can I encrypt it again using the same 

>> encryption settings it had, which I don't actually know? . For 

>> example, I know only the owner password, but not the user password.

>> 

>>    

>> 

>>    

>> 

>> Best regards,

>> 

>> Hesham

>> 

>>    

>> 

>>    

>> 

>> 

>> 

>> ---

>> This email has been checked for viruses by Avast antivirus software.

>>  <https://www.avast.com/antivirus> https://www.avast.com/antivirus

>> 

> 

> ---------------------------------------------------------------------

> To unsubscribe, e-mail:  <mailto:[email protected]> 
> [email protected]

> For additional commands, e-mail:  <mailto:[email protected]> 
> [email protected]

> 

> 

> 

> ---------------------------------------------------------------------

> To unsubscribe, e-mail:  <mailto:[email protected]> 
> [email protected]

> For additional commands, e-mail:  <mailto:[email protected]> 
> [email protected]

> 

 

 

---------------------------------------------------------------------

To unsubscribe, e-mail:  <mailto:[email protected]> 
[email protected]

For additional commands, e-mail:  <mailto:[email protected]> 
[email protected]

 

Reply via email to