PXC_SecurityMethod

The PDF-XChange Viewer for End Users
+++ FREE +++

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

m.holik
User
Posts: 21
Joined: Tue Dec 20, 2011 5:47 pm

PXC_SecurityMethod

Post by m.holik »

Hi
I am using your tracker software (ToolsV4SDK), looking through C# examples to use PXC_EnableSecurityEX, but I can't seem to find any example.
Also can you please tell me where the PXC_SecurityMethod struct or enum is defined? I can't seem to find it in your files XCPro40_Declares.cs or in the PDFXC_Funcs.cs files.
Thanks appreciate your help.
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: PXC_SecurityMethod

Post by Walter-Tracker Supp »

It looks as though somebody neglected to include a typedef for that enum in the C# wrapper / example code, I believe because this function (PXC_EnableSecurityEx) was added as a newer feature.

The values for PXC_SecurityMethod are (as found on page 23 of the PDF Tools SDK v4 documentation):

1. psm_None, value: 0. Security disabled. Parameters UserPwd and OwnerPwd will be ignored.
2. psm_RC4, value: 1. RC4 encryption method will be used. RC4 can has 40-bit or 128-bit key length.
3. psm_AES, value: 2. AES 128 bit encryption method will be used.
4. psm_AES256, value: 3. AES 256 bit encryption method will be used.

To set the document permissions, you must also use one of the PXC_SetPermissions functions (PXC_SetPermissions, PXC_SetPermissions40, PXC_SetPermissions128, PXC_SetPermissions256) after PXC_EnableSecurityEX().
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: PXC_SecurityMethod

Post by Walter-Tracker Supp »

Please try the attached file (PDFXC_Funcs.cs).

All that was done was to add the following declaration to PDFXC_Funcs.cs in region "Document operations":

Code: Select all

        [DllImport("pxclib40")]
        public static extern int PXC_EnableSecurityEx(int pdf, PXC_Securitymethod nMethod, [MarshalAs(UnmanagedType.LPStr)]string UserPwd, [MarshalAs(UnmanagedType.LPStr)]string OwnerPwd);
And in region "Structures and constants" add the enum definition:

Code: Select all

        public enum PXC_Securitymethod
        {
            psm_None = 0,
            psm_RC4 = 1,
            psm_AES = 2,
            psm_AES256 = 3
        }
You do not have the required permissions to view the files attached to this post.
m.holik
User
Posts: 21
Joined: Tue Dec 20, 2011 5:47 pm

Re: PXC_SecurityMethod

Post by m.holik »

Thanks for the help.

Also would like to know if you have any code example to use the PXC_EnableSecurityEx method. I seem to be crashing when I use this method when both the userPwd and ownerPwd have values.
Thank you.
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: PXC_SecurityMethod

Post by Walter-Tracker Supp »

m.holik wrote:Thanks for the help.

Also would like to know if you have any code example to use the PXC_EnableSecurityEx method. I seem to be crashing when I use this method when both the userPwd and ownerPwd have values.
Thank you.

Sure. I have modified the example PDFXCDemo (C:\Program Files\Tracker Software\PDF-XChange PRO 4 SDK\Examples\SDKExamples\C#Examples\PDFXCDemo):

In frmMain.cs, search for the line containing:

Code: Select all

PXC_WriteDocumentExA(pdf, m_DstFileName, m_DstFileName.Length, fl, "");
And add a call to PXC_EnableSecurityEx() right before that, as follows:

Code: Select all

            
                        PDFXC_Funcs.PXC_EnableSecurityEx(pdf, PDFXC_Funcs.PXC_Securitymethod.psm_AES, "userpwd", "ownerpwd");
			PDFXC_Funcs.PXC_WriteDocumentExA(pdf, m_DstFileName, m_DstFileName.Length, fl, "");
			PDFXC_Funcs.PXC_ReleaseDocument(pdf);
You will find that the passwords are set properly.

I do not think that it is strictly necessary to set security just before writing; I have also successfully done it by placing the call to PXC_EnableSecurityEx() just after PXC_NewDocument().
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: PXC_SecurityMethod

Post by Walter-Tracker Supp »

Also, if this does not help, please show an example of your code so we can try to diagnose what is going wrong.

-Walter
m.holik
User
Posts: 21
Joined: Tue Dec 20, 2011 5:47 pm

Re: PXC_SecurityMethod

Post by m.holik »

Thanks for your help. Will try your suggestions and see if it works.
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7445
Joined: Wed Mar 25, 2009 10:37 pm

Re: PXC_SecurityMethod

Post by Paul - PDF-XChange »

looking forward to hearing. :-)
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
m.holik
User
Posts: 21
Joined: Tue Dec 20, 2011 5:47 pm

Re: PXC_SecurityMethod

Post by m.holik »

Thanks it worked. I was crashing when reading the document programatically since it was encrypted.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19930
Joined: Mon Jan 12, 2009 8:07 am

Re: PXC_SecurityMethod

Post by Stefan - PDF-XChange »

Great to hear! :)

Cheers,
Stefan