Michael A Michael A - 1 month ago 18
Java Question

Reading encrypted pdf Metadata without decrypting the file

I am using iText to encrypt PDF files:

stamp.setEncryption(hardPasswordByte,
hardPasswordByte,
PdfWriter.ALLOW_PRINTING,
PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);


Notice I am specifying
PdfWriter.DO_NOT_ENCRYPT_METADATA
.

But when I try only to read the Document Metadata like this (without decrypting the Document):

PdfReader ReadInputPDF = new PdfReader(path);
byte Document_MetaData[] = ReadInputPDF.getMetadata();


I get "Bad user password" exception.

Is there a way to read the metadate with out decrypting the document?

Answer

So, as mkl said the PdfWriter.DO_NOT_ENCRYPT_METADATA simply sets the MetaData which can be read as a clear text. Using Java i can simply use InputStream and read the file, searching for the metadata.

Comments