Encrypt128, DocEncrypt128

The Encrypt128 and DocEncrypt128 methods can be used to password protect a PDF document and restrict users to viewing, modifying or even printing the document. This function requires a call to Document.SetLicenseKey before it can be used. The Encrypt128 and DocEncrypt128 methods use 128 bits encryption compatible with Adobe® Acrobat® 5 and higher.

 

Syntax

ActiveX:

System.Boolean Encrypt128(System.String OwnerPassword, System.String UserPassword, System.Int32 Permissions)

DLL:

int DocEncrypt128(EXTDOCHANDLE edhDocument, LPCWSTR szOwnerPassword, LPCWSTR szUserPassword, DWORD dwPermissions)

 

Parameters

OwnerPassword, szOwnerPassword

Owner password.

UserPassword, szUserPassword

User password.

Permissions, dwPermissions

Options to restrict users opening the document using the User password.

 

Permission Type

Value (Hex)

Value (Dec)*

No permission.

0xFFFFF0C0

-3904

Enable Printing (low resolution)

0xFFFFF0C0 | 0x000004

-3904 + 4

Enable document modification, including document assembly.

0xFFFFF0C0 | 0x000008

-3904 + 8

Enable copying text and graphics, and support of accessibility to users with disabilities or for other purposes.

0xFFFFF0C0 | 0x000010

-3904 + 16

Enable adding and changing notes, and fill-in existing interactive form fields (including signature fields).

0xFFFF0C0 | 0x000020

-3904 + 32

Enable only fill-in existing interactive form fields (including signature fields).

0xFFFF0C0 | 0x000100

-3904 + 256

Enable extraction text and graphics (in support of accessibility to users with disabilities or for other purposes)

0xFFFF0C0 | 0x000200

-3904 + 512

Enable document assembly which includes: insert, rotate or delete pages and create bookmark or thumbnail images, but not document modification.

0xFFFF0C0 | 0x000400

-3904 + 1024

Enable High-Quality Printing, but the if "Enable Printing" has to be enabled.

0xFFFF0C0 | 0x000800

-3904 + 2048

(*) NOTE: Converting from HEX DWORD, unsigned and 32-bit unit of data

 

edhDocument

Handle Returned by DocOpen.

 

Return Value

The return value is True if the Encrypt128 method succeed. Otherwise, False If the Encrypt128 method fails. his method launches an exception if the encryption feature is not available.

 

The return value is zero if the DocEncrypt128 method succeed. If the DocEncrypt128 method fails, a negative value will returned.

 

 

Remarks

In the case of the evaluation version, the passwords are always set to "aaaaaa" (Owner Password) and "bbbbbb" (User Password) and cannot be changed.

To combine multiple options, use hexadecimal 0xFFFFF0C0 or decimal -3904 plus the values 4, 8, 16 or 32.

E.g. to enable both printing and adding notes, use hexadecimal 0xFFFFF0C0 | 0x000004 |  0x000020, or decimal -3904 + 4 + 32 = -28. To disable all 4 options, use hexadecimal 0xFFFFF0C0 or decimal -3904.

 

Member of CDIntfEx.Document.

 

 

Owner and User Passwords

Two passwords are associated to an encrypted PDF document. The owner password is for the author of the document, and the user password for the destination or user of the document.

The owner password is optional and allows the author having this password to do any operation he/she wishes on this document, including modifying its security settings.  

It can be blank, but the PDF document won' t be fully protected.

 

The user password is optional and can be one of the following:

User Password Option

Description

A blank password

The user is not prompted for a password when opening a document, but is restricted to the operations allowed by the author.

The same password as the owner

The user is prompted for a password and the author of the document will not be able to open this document as an owner to change its security settings.

A password different from the owner

The user will not be able to open the document unless he/she enters a valid password. When a valid password is entered, the document can be viewed but its usage is `restricted to the operations allowed by the author.

The password dialog can be forced to appear if the SHIFT key is pressed while pressing the open bottom of the "File Open" dialog. This way, the application user can enter the owner password even if the user password is blank.

 

User Settings

Enable changing the document content. When this option is checked, the user is allowed to change the contents of the PDF document.

 

These options are managed by the tool used to view the document and not by the PDF Converter. Once a valid password is entered, it is up to the viewer or editor to make sure that these security settings are respected.

 

Example

<Flags()>

Public Enum PERMISSIONS As Integer

    NO_PERMISSION = &HFFFFF0C0

    ENABLE_PRINTING = &H4

    ENABLE_DOCUMENT_MODIFICATION = &H8

    ENABLE_COPYING_TEXT_GRAPHICS = &H10

    ENABLE_ADDING_CHANGING_NOTES = &H20

    ENABLE_ONLY_FILL_IN = &H100

    ENABLE_EXTRACTION = &H200

    ENABLE_ONLY_ASSEMBLY = &H400

    ENABLE_HIGH_QUALITY = &H800

End Enum

 

Public Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

    ' Declare a new cdintfex document if it does not exist in the form.

    Dim pdfDoc As New CDIntfEx.Document

 

    ' The SetLicenseKey method should be called after creating an object of type 

    ' CDIntfEx.Document to activate the advanced methods that require the object 

    ' activation code to work properly

    pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Open the document

    pdfDoc.Open("c:\temp\test.pdf")

 

    ' Set Encryption

    pdfDoc.Encrypt128("owner123", "user123", PERMISSIONS.NO_PERMISSION Or PERMISSIONS.ENABLE_PRINTING Or PERMISSION.ENABLE_HIGH_QUALITY)

 

    ' Save the document

    pdfDoc.Save("c:\temp\Encrypted.pdf")

End Sub

[Flags]

public enum PERMISSIONS

{

    NO_PERMISSION = unchecked((int)0xFFFFF0C0),

    ENABLE_PRINTING = 0x4,

    ENABLE_DOCUMENT_MODIFICATION = 0x8,

    ENABLE_COPYING_TEXT_GRAPHICS = 0x10,

    ENABLE_ADDING_CHANGING_NOTES = 0x20,

    ENABLE_ONLY_FILL_IN = 0x100,

    ENABLE_EXTRACTION = 0x200,

    ENABLE_ONLY_ASSEMBLY = 0x400,

    ENABLE_HIGH_QUALITY = 0x800

}

 

public void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Converter Evaluation";

    const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

 

    // Declare a new cdintfex document if it does not exist in the form.

    CDIntfEx.Document pdfDoc = new CDIntfEx.Document();

 

    // The SetLicenseKey method should be called after creating an object of type 

    // CDIntfEx.Document to activate the advanced methods that require the object 

    // activation code to work properly

    pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Open the document

    pdfDoc.Open(@"c:\temp\test.pdf");

 

    // Set Encryption

    pdfDoc.Encrypt128("owner123", "user123", (int)(PERMISSIONS.NO_PERMISSION | PERMISSIONS.ENABLE_PRINTING | PERMISSIONS.HIGH_QUALITY));

 

    // Save the document

    pdfDoc.Save("c:\temp\Encrypted.pdf");

}

// PDF Converter Cpp.cpp : Defines the entry point for the console application.

// 

#include <Windows.h>

#include <string>

#include <iostream>

#include "CdIntf.h"

#pragma comment (lib, "CDIntf.lib")

 

using namespace std;

 

enum PERMISSIONS 

{

    NO_PERMISSION = 0xFFFFF0C0,

    ENABLE_PRINTING = 0x4,

    ENABLE_DOCUMENT_MODIFICATION = 0x8,

    ENABLE_COPYING_TEXT_GRAPHICS = 0x10,

    ENABLE_ADDING_CHANGING_NOTES = 0x20,

    ENABLE_ONLY_FILL_IN = 0x100,

    ENABLE_EXTRACTION = 0x200,

    ENABLE_ONLY_ASSEMBLY = 0x400,

    ENABLE_HIGH_QUALITY = 0x800

};

 

int main()

{

     // Constants for Activation codes

    #define strLicenseTo  "Amyuni PDF Converter Evaluation"

    #define strActivationCode "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

    // Declare a new cdintfex document if it does not exist in the form.

    EXTDOCHANDLE pdfDoc;

 

    // The SetLicenseKey method should be called after creating an object of type 

    // CDIntfEx.Document to activate the advanced methods that require the object 

    // activation code to work properly

    SetLicenseKeyA(strLicenseTo, strActivationCode);

 

    // Open the document

    LPBYTE passWord = nullptr;

    DocOpenA(&pdfDoc, "c:\\temp\\test.pdf", passWord);

 

    // Set Encryption

    DocEncrypt128A(pdfDoc, "owner123", "user123", PERMISSIONS::NO_PERMISSION | PERMISSIONS::ENABLE_PRINTING | PERMISSIONS::ENABLE_HIGH_QUALITY);

 

    // Save the document

    DocSaveA(pdfDoc, "c:\\temp\\Encrypted.pdf");

 

    // Destroy pdfDoc object

    DocClose(pdfDoc);

    pdfDoc = nullptr;    

 

    return 0;

}

package Example;

 

import com.jacob.activeX.ActiveXComponent;

import com.jacob.com.Dispatch;

import com.jacob.com.Variant;

 

public class Sample {

    public enum PERMISSIONS 

    {

        NO_PERMISSION (0xFFFFF0C0),

        ENABLE_PRINTING (0x4),

        ENABLE_DOCUMENT_MODIFICATION (0x8),

        ENABLE_COPYING_TEXT_GRAPHICS (0x10),

        ENABLE_ADDING_CHANGING_NOTES (0x20)

        ENABLE_ONLY_FILL_IN (0x100),

        ENABLE_EXTRACTION (0x200),

        ENABLE_ONLY_ASSEMBLY (0x400),

        ENABLE_HIGH_QUALITY (0x800);

        public int value;

        public PERMISSIONS(int value)

        {

            this.value = value;

        }

        public Object value(){

            return value;

        }

    }

    public static void main(String[] args)

    {

        // Constants for Activation codes

        String strLicenseTo  = "Amyuni PDF Converter Evaluation";

        String strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

 

        // Declare a new cdintfex document if it does not exist in the form.

        ActiveXComponent pdfDoc = new ActiveXComponent("CDIntfEx.Document.6.5"); 

 

        // The SetLicenseKey method should be called after creating an object of type 

        // CDIntfEx.Document to activate the advanced methods that require the object 

        // activation code to work properly

        Dispatch.call(pdfDoc, "SetLicenseKey", strLicenseTo, strActivationCode);

 

        // Open the document

        Dispatch.call(pdfDoc, "Open", "c:\\temp\\test.pdf");

 

        // Set Encryption

        Dispatch.call(pdfDoc, "Encrypt128", "owner123", "user123", PERMISSIONS.NO_PERMISSION.value + PERMISSIONS.ENABLE_PRINTING.value + PERMISSIONS.ENABLE_HIGH_QUALITY.value);

 

        // Save the document

        Dispatch.call(pdfDoc, "Save", "c:\\temp\\Encrypted.pdf");

 

        // Destroy pdfDoc object

        pdfDoc = null; 

    }

}

$PERMISSIONS = @{

    NO_PERMISSION = 0xFFFFF0C0

    ENABLE_PRINTING = 0x4

    ENABLE_DOCUMENT_MODIFICATION = 0x8

    ENABLE_COPYING_TEXT_GRAPHICS = 0x10

    ENABLE_ADDING_CHANGING_NOTES = 0x20

    ENABLE_ONLY_FILL_IN = 0x100

    ENABLE_EXTRACTION = 0x200

    ENABLE_ONLY_ASSEMBLY = 0x400

    ENABLE_HIGH_QUALITY = 0x800

}

 

# Constants for Activation codes

$strLicenseTo  =  "Amyuni PDF Converter Evaluation"

$strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

#Declare a new cdintfex document if it does not exist in the form.

$pdfDoc = New-Object -ComObject CDIntfEx.Document.6.5

 

#The SetLicenseKey method should be called after creating an object of type 

#CDIntfEx.Document to activate the advanced methods that require the object 

#activation code to work properly

[System.__ComObject].InvokeMember('SetLicenseKey', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, @($strLicenseTo, $strActivationCode))

 

#Open the document

[System.__ComObject].InvokeMember('Open', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\test.pdf") 

 

#Set Encryption

[System.__ComObject].InvokeMember('Encrypt128', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, 

    @("owner123", "user123", $PERMISSIONS::NO_PERMISSION -bOr $PERMISSIONS::ENABLE_PRINTING -bOr $PERMISSIONS::ENABLE_HIGH_QUALITY))

 

#Save the document

[System.__ComObject].InvokeMember('Save', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\Encrypted.pdf") 

 

#Destroy pdfDoc object

$pdfDoc = $null

' Permissions

Const NO_PERMISSION = -3904

Const ENABLE_PRINTING = 4

Const ENABLE_DOCUMENT_MODIFICATION = 8

Const ENABLE_COPYING_TEXT_GRAPHICS = 16

Const ENABLE_ADDING_CHANGING_NOTES = 32

Const ENABLE_ONLY_FILL_IN = 256

Const ENABLE_EXTRACTION = 512

Const ENABLE_ONLY_ASSEMBLY = 1024

Const ENABLE_HIGH_QUALITY = 2048

 

' Constants for Activation codes

Const strLicenseTo = "Amyuni PDF Converter Evaluation"

Const strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

' Declare a new Document object

Dim pdfDoc

Set pdfDoc = CreateObject("CDIntfEx.Document.6.5")

 

' The SetLicenseKey method should be called after creating an object of type 

' CDIntfEx.Document to activate the advanced methods that require the object 

' activation code to work properly

pdfDoc.SetLicenseKey strLicenseTo, strActivationCode

 

' Open the document

pdfDoc.Open "c:\temp\test.pdf"

 

' Set Encryption

pdfDoc.Encrypt128 "owner123", "user123", NO_PERMISSION + ENABLE_PRINTING + ENABLE_HIGH_QUALITY

 

' Save the document

pdfDoc.Save "c:\temp\Encrypted.pdf"

 

' Destroy pdfDoc object

Set pdfDoc = Nothing