From users-return-10690-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Tue Jan 9 15:38:04 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id B2A69180718 for ; Tue, 9 Jan 2018 15:38:04 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id A2B1E160C3F; Tue, 9 Jan 2018 14:38:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CC0D9160C13 for ; Tue, 9 Jan 2018 15:38:03 +0100 (CET) Received: (qmail 78201 invoked by uid 500); 9 Jan 2018 14:38:02 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Received: (qmail 78186 invoked by uid 99); 9 Jan 2018 14:38:02 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Jan 2018 14:38:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id BA1D31A0E17 for ; Tue, 9 Jan 2018 14:38:01 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.889 X-Spam-Level: * X-Spam-Status: No, score=1.889 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, T_KAM_HTML_FONT_INVALID=0.01] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id ku-GadhXt36P for ; Tue, 9 Jan 2018 14:37:59 +0000 (UTC) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 8C53A5FBEE for ; Tue, 9 Jan 2018 14:37:58 +0000 (UTC) Received: by mail-wm0-f41.google.com with SMTP id i11so21022008wmf.4 for ; Tue, 09 Jan 2018 06:37:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:references:in-reply-to:subject:date:message-id:mime-version :thread-index:content-language; bh=iTfpE7BVbfvCFlWIarlZrQZmZT7Wz+XkHSLgzMUs5NI=; b=pO7GHBZyGV1Pzw4zP4IhA02eOsNjAxrkk8bjjioIoUShmEVget2hGOR4KxyE8tfAJI tBHHvB++OR8chef2n73M7b6c1HhV4WW8YrnzIqGN/OKX6rYIsiP0DHQvxpzkvRKYSUKl qVycrm4L2CVopdQtWTl7+zt1BR3nxr0rLnwVQYVLmDygU75B7doYJ7J1cmigfrkyMfqh 1Qbfpawaa9q2RFomwF9SiRjeYDVtH8AzTv7piQ7i1cyd82FSzgPbCjpUFCIgBjOh7t1j CVF8XzwVT6M28/k8hLoGAz++jUiq+W10ZWfY9zaY6HLmPbTAoi9C2/ewvXfbvB5jPOzb mufQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:references:in-reply-to:subject:date :message-id:mime-version:thread-index:content-language; bh=iTfpE7BVbfvCFlWIarlZrQZmZT7Wz+XkHSLgzMUs5NI=; b=mefoaTHj5ZKyDlnXIttxhb1w+y7p961WsH0eSieAzmHY0iV5SDBwHgAZoY/2ewoPPp H0R6hKbLN/w1uVCW3fBZU4bstFpunm9Ok1TYXPFqQfQ3CWnwTGQ75PlymPFnET81UWUq fCHTgf8n67upVaAImwM7TiZyZg1/4MuHK2q0kumwBE9mSM4kgdjv3acJDRZCABinneNJ ymoIUcbcZnmcdsFn0AJSU4bNhhmfEZX5mp60JaiPQJPoCxGAps3ak5v7CTn6It4lDuR1 qFZ5DVh/IQkTPxIAbrln14ar4webxznHmjoH6qki8wZrZyZX7Vbh637ljzezwgaToGE9 vV0g== X-Gm-Message-State: AKGB3mKP29En4oujbwHGK4tPv3tD1bcn47qPx6X22xnKiFFqdAEK6kFD 4mhjYyq5V6CmRvi3Db4xQ0OXxQ== X-Google-Smtp-Source: ACJfBosFEPSBqnmlNvOJ8CY43J+4Edd9mMyUbhQX9BWhDRLT2ajAJOFCtNIPE/xPHk23tQa5ZZxGZw== X-Received: by 10.28.140.1 with SMTP id o1mr13304215wmd.27.1515508677536; Tue, 09 Jan 2018 06:37:57 -0800 (PST) Received: from LAPTOP7UEFS44D ([156.212.24.82]) by smtp.gmail.com with ESMTPSA id q7sm10928043wrf.31.2018.01.09.06.37.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 06:37:56 -0800 (PST) From: "Hesham Gneady" To: References: <18c7201d3846c$f37bd630$da738290$@gmail.com> <10e3e29c-dcaa-af8f-54c9-340f1a222dcd@t-online.de> <18cea01d3852d$67e1a520$37a4ef60$@gmail.com> In-Reply-To: Subject: RE: Decrypt PDF to edit it then encrypt it Date: Tue, 9 Jan 2018 16:37:53 +0200 Message-ID: <196aa01d38957$6fad1310$4f073930$@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_196AB_01D38968.33385410" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQK1LNz9mnXA0B0N7YyA61v7oBPPMQICWBaOAa3XVPgBkVPQFaF+SNUw Content-Language: en-us X-Antivirus: Avast (VPS 180109-0, 01/09/2018), Outbound message X-Antivirus-Status: Clean ------=_NextPart_000_196AB_01D38968.33385410 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks Tilman! I have tested your code & it works fine =F0=9F=98=8A =20 =20 Best regards, Hesham=20 =20 -------------------------------------------------------------------------= ------------------------- Included Message: =20 here's some code... I'm also adding it to our tests as some extra fun. =20 =20 PDEncryption encryption =3D doc.getEncryption(); int revision =3D encryption.getRevision(); if (revision < 5) { StandardSecurityHandler standardSecurityHandler =3D new = StandardSecurityHandler(); int keyLengthInBytes =3D encryption.getVersion() =3D=3D 1 ? = 5 :=20 encryption.getLength() / 8; byte[] computedUserPassword =3D = standardSecurityHandler.getUserPassword( ownerpassword.getBytes(Charsets.ISO_8859_1), encryption.getOwnerKey(), revision, keyLengthInBytes); =20 } =20 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). =20 Tilman =20 Am 04.01.2018 um 08:26 schrieb Hesham Gneady: > Thanks a lot Tilman .. I will try that =F0=9F=98=8A >=20 >=20 >=20 > Best regards, > Hesham >=20 > ---------------------------------------------------------------------- > ---------------------------- > Included Message: >=20 > 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. >=20 > 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(). >=20 > Tilman >=20 > Am 03.01.2018 um 09:29 schrieb Hesham Gneady: >> Hello, >>=20 >> =20 >>=20 >> I have a PDF file that has an owner password & user password. I'd=20 >> like to decrypt it using the owner password, make some modifications=20 >> to it, then encrypt it back and save it. I did the first part=20 >> successfully, but how can I encrypt it again using the same=20 >> encryption settings it had, which I don't actually know? . For=20 >> example, I know only the owner password, but not the user password. >>=20 >> =20 >>=20 >> =20 >>=20 >> Best regards, >>=20 >> Hesham >>=20 >> =20 >>=20 >> =20 >>=20 >>=20 >>=20 >> --- >> This email has been checked for viruses by Avast antivirus software. >> https://www.avast.com/antivirus >>=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: = users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: = users-help@pdfbox.apache.org >=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: = users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: = users-help@pdfbox.apache.org >=20 =20 =20 --------------------------------------------------------------------- To unsubscribe, e-mail: = users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: = users-help@pdfbox.apache.org =20 ------=_NextPart_000_196AB_01D38968.33385410--