Is this byte array a password protected PDF document?

I have an array of bytes in C # and I need to know if it is a password protected PDF document. How can I make this determination?

I am checking the PDF document for a cookie to determine if it is a PDF document, but I do not know what is best when determining if a password is protected.

I do not need to open the document (although as long as no user interface is required), this is a background process, I am fine with this if it helps).

I just need to know if there is a password in this PDF.

EDIT: If you specify iTextSharp, I would really appreciate if you would specify a specific resource in this API that addresses this issue.

+6
source share
2 answers

There are several password protection options for PDFs, some of which are defined by Adobe (the "standard"), and so-called "alternative security handlers" can be used as part of the standard.

In any case, everything can be detected mainly by checking the corresponding dictionaries, as described on pages 115 - 136 of the PDF specification - see http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en /devnet/acrobat/pdfs/pdf_reference_1-7.pdf

+2
source

Docotic.Pdf library can be used to perform such a check.

The library provides a group of methods that can be used to check if a byte, stream, or file contains a password-protected PDF document.

Please take a look at a sample that shows how to check if an existing PDF is protected .

Disclaimer: I work for a company.

+2
source

Source: https://habr.com/ru/post/894559/


All Articles