Working with 40-bit RC4 PDF security.

Q:

How would the following be changed to restrict the StdSecurity object
to 40bit RC4?

PDFNet::SetResourcesPath(PdfTronResourcePath);
SecurityManager& sec_mgr = SecurityManagerSingleton::Instance();
sec_mgr.RegisterSecurityHandler("Standard",
SDF::SecurityDescriptor("Standard Security",
MySecurityHandler::Create));
----
A:
The simplest way to create 40-bit RC4 security handlers is as
follows:

StdSecurityHandler sec = new
StdSecurityHandler(StdSecurityHandler.AlgorithmType.e_RC4_40);

Altertantively if you create a new security handler as 'new
StdSecurityHandler(40, 1)' you need to set the algorithm revision to
'2' because Acrobat 3 didn't support the full permission set that was
available in later versions of PDF.

For example:

// In C#
StdSecurityHandler new_handler = new StdSecurityHandler(40, 1);
new_handler.ChangeRevisionNumber(2);
new_handler.ChangeUserPassword(new
System.Text.UTF8Encoding().GetBytes("user"));
new_handler.ChangeMasterPassword(new
System.Text.UTF8Encoding().GetBytes("owner"));

pdfdoc.SetSecurityHandler(new_handler);

StdSecurityHandler constructor accepting AlgorithmType.e_RC4_40
automatically calls ChangeRevisionNumber(2).

In case you would like to process only 40-bit RC4 secured PDF
documents you could extend your 'MySecurityHandler' to include code to
check the current version of the security hander (e.g. using
GetKeyLength(), GetRevisionNumber(), etc) and to throw an exception if
the document does not meet your requirements.