OpenPDF
OpenPDF copied to clipboard
"Unknown encryption type R = 6" support AES256
It seems that the first AES256 encrypted pdf's are out in the wild
https://stackoverflow.com/questions/50822874/unknown-encryption-type-opening-pdf-file
I guess they should be supported
I tried this once but failed and didn't have the time to investigate further. Seems not so easy...
Created with
Damn also had a document with this error now :-( Seems more and more docs are in the wild using this standard
Here is an another example of the 256-bit AES encrypted file: https://pratiyogitaabhiyan.in/wp-content/uploads/2020/09/Indian-National-Movement-Phase-III-1935-1947-NotesMCQ-PDF-pratiyogitaabhiyan.in_.pdf
Qpdf output:
>qpdf --show-encryption Indian-National-Movement_1.pdf
WARNING: Indian-National-Movement_1.pdf: file is damaged
WARNING: Indian-National-Movement_1.pdf (offset 1116099): xref not found
WARNING: Indian-National-Movement_1.pdf: Attempting to reconstruct cross-reference table
R = 5
P = -1852
User password =
Supplied password is user password
extract for accessibility: not allowed
extract for any purpose: not allowed
print low resolution: allowed
print high resolution: allowed
modify document assembly: not allowed
modify forms: not allowed
modify annotations: not allowed
modify other: not allowed
modify anything: not allowed
stream encryption method: AESv3
string encryption method: AESv3
file encryption method: AESv3
qpdf: operation succeeded with warnings
To fix the problem of opening files with 256-bit AES encryption this part from "itext7-dotnet" repository should be brought into this repository somewhere here:
https://github.com/LibrePDF/OpenPDF/blob/116b38cdbe30385161444976a2c418446fdaf0a5/openpdf/src/main/java/com/lowagie/text/pdf/PdfReader.java#L728-L737
Pull requests welcome!
To fix the problem of opening files with 256-bit AES encryption this part from "itext7-dotnet" repository should be brought into this repository somewhere here:
Beware not to really copy from there to here. While being inspired by it certainly is ok, a more or less verbatim copy of too much code might cause license issues.
@mkl-public I get you point.
Actually I saved the link with AES256 implementation in iText because it is always nice to have a working code and you can always take a look into the alternative implementation, if you got stuck.
BTW here is the same part on Java, which is more useful for us, as long as OpenPDF is written on Java.
From the other side the encryption algorithm should be more or less the same, as long as we need to get the same result.
From the third side it looks like we still can copy the code from iText to OpenPDF:
- iText is licensed under AGPL
- OpenPDF is licensed under LGPLv2.1
- Borrowing code from (A)GPL to LGPLv.2.1 is in general allowed, see compatibility matrix and also the first paragraph of the answer here
So this mean, that if you copy code from AGPL, into the LGPL project, the copied code still is AGPL. And OpenPDF would become AGPL too, which is not the intend of OpenPDF. It should remain LGPL, so it can still be used in closed source projects.
https://www.gnu.org/licenses/gpl-faq.en.html#UnreleasedModsAGPL
See also PDFBox at https://issues.apache.org/jira/browse/PDFBOX-4413 and https://issues.apache.org/jira/browse/PDFBOX-1594
Similar issues:
com.lowagie.text.exceptions.InvalidPdfException: Unknown encryption type R = 5
at com.lowagie.text.pdf.PdfReader.readPdf(PdfReader.java:618)
at com.lowagie.text.pdf.PdfReader.<init>(PdfReader.java:184)
at com.lowagie.text.pdf.PdfReader.<init>(PdfReader.java:168)
Did anybody try to implement it? Very interested in this as well!
@mkl-public , any chance for a PR maybe? :)
Yes there is a working branch at least for R=6 (not the deprecated R=5) I did the quality test and it is running perfectly for me since quite a while.. @mkl-public wanted to add a PR here some time ago but maybe he's busy with some other things...
@bsanchezb, @Lonzak,
ok ok, the PR is there, it's #802.
Just to make sure the nature of the fix is correctly understood: It adds support for password based AES256 (ISO 32000-2) - R=6 - but not for the interim AES256 (ISO 32000-1 + Adobe Developer Extensions) - R=5 - which has been deprecated in ISO 32000-2. Thus, it solves the issue as originally posted by Ralf Hauser but it won't help with documents as referenced by mspnr (Indian-National-Movement_1.pdf) or as encountered by h2cone.