Custom PDF security handler in JAVA

317 views
Skip to first unread message

Support

unread,
Jan 5, 2011, 7:30:54 PM1/5/11
to PDFTron PDFNet SDK
Q: I am using PDFNet SDK for Java and am trying to implement a custom
security handler because our PDFs are protected with custom security.

If I open pdf document secured by custom security handler I get this
error:
Exception:
Message: Requested security handler was not found.
Filename : SecurityManager
at pdftron.PDF.PDFDoc.initSecurityHandler(PDFDoc.java:293)

Security handler has it's own name:

<</StmF/StdCF/P -3904/Filter/FOOBAR/R 4/Length 128/CF

How can I register custom security handler in java?

I am missing class SecurityManager in java as is described on
http://www.pdftron.com/pdfnet/documentation.html#security_custom .

-------------------
A: SecurityManager is currently not available in the Java version,
however there are couple of workarounds:

- In case you are developing a new security scheme it may be better to
encrypt the entire document (or sections of the document). This would
make it much more difficult to remove your proprietary encryption that
standard PDF security.

- In case you are dealing with existing PDF files with custom security
you could fetch the encryption dictionary before calling
InitSecurityHnadler() and perform the custom decryption on this
dictionary before calling InitSecurityHandler(). You would effectively
need to decrypt required entries in the encryption dictionary and
change the security handler to Standard.

For example:

PDFDoc doc = new PDFDoc(...);
Obj enc = doc.getTrailer().findObj("Encrypt");
if (enc == null) ... not encrypted

// Get and decode the values or P, O, and U entry using your
proprietary algorithm...
int permissions = (int) enc.findObj("P").getNumber();
byte[] userkey = enc.findObj("U").getBuffer();
byte[] ownerkey = enc.findObj("O").getBuffer();
.... decode p, u, o
enc.putNumber("P", permissions);
enc.putString("P", userkey);
enc.putString("O", ownerkey);

enc.putName("Filter", "Standard");

// now initialize the document with the standard handler...
doc.initSecurityHandler();
...


Reply all
Reply to author
Forward
0 new messages