How can I find out encryption type and strength before viewing or processing a PDF document?

Q: I have a situation in which I need to ascertain the type and the
level of encryption before the correct password is given. This is to
allow the implementation of export regulations to keep from opening
encrypted documents with greater than 40bit RC4 encryption. In
previous instances, I have used PDFDoc::InitSecurityHandler(custom
data) to allow me to access the customer data inside a custom security
handler and pass the results back to the caller. Since Initialize is
missing from the SecurityHandler declaration, how to I access the
custom data field?
------
A: You can access the content of encryption dictionary before
initializing a security handler as follows:

PDFDoc pdfdoc = ...
Obj trailer = pdfdoc.GetTrailer();
Obj encrypt = trailer.FindObj("Encrypt");
... access custom data ...
pdfdoc.InitSecurityHandler();

Alternatively, if you are dealing with standard PDF security you can
simply obtain all information about the security handler after calling
pdfdoc.InitSecurityHandler(). For example:

PDFDoc pdfdoc = ...
pdfdoc.InitSecurityHandler();
SecurityHandler sec_hdlr = pdfdoc.GetSecurityHandler();
int len = sec_hdlr.GetKeyLength();
int id = sec_hdlr.GetEncryptionAlgorithmID();
...

Depending on the returned values you can choose to prevent the user
from processing the file or opening PDF within the viewer.

Using the latest version of PDFNet it is also possible to implement a
custom security handler (by registering a class derived from
SecurityHandler), however, based on your requirements, this would be
more complex than necessary.