Encrypt and Encrypt128 Methods

The Encrypt method secures the PDF document and prevents it from unauthorized access. Two passwords, the owner password and user password, are associated with an encrypted PDF document. The Encrypt128 method provides 128-bit encryption.

Syntax

C++:

HRESULT Encrypt(BSTR OwnerPassword, BSTR UserPassword, long Options)

HRESULT Encrypt128(BSTR OwnerPassword, BSTR UserPassword, long Options)

C#:

void Encrypt (string ownerPassword, string userPassword, long Options)

void Encrypt128 (string ownerPassword, string userPassword, long Options)

VB:

Sub Encrypt (OwnerPass As String, UserPass As String, Permissions As Long)

Sub Encrypt128 (OwnerPass As String, UserPass As String, Permissions As Long)

Parameters

OwnerPass

Owner password for the author 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. The owner password can be blank, same password as the user, or a password different from the user.

UserPass

This is the user password for the destination or user of the document. The user password is optional and can be one of the following:

Blank password

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

Same as Owner password

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.

Different from owner password

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 restricted to the operations allowed by the author.

 

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

 

Permissions

Permissions to user.

 

Permission Type

Value

No permission.

&HFFFFFFC0

Enable printing.

&HFFFFFFC0 + 4

Enable changing the document.

&HFFFFFFC0 + 8

Enable copying text and graphics.

&HFFFFFFC0 + 16

Enable adding and changing notes.

&HFFFFFFC0 + 32

 

Example in VB:

pdf.Open "test.pdf", ""

'protect a document using an owner and a user password

pdf.Encrypt "owner" ,"user", &HFFFFFFC0

'to enable printing + adding and changing notes

'pdf.Encrypt "owner", "user", &HFFFFFFC0 + 4 + 32

pdf.Save "test1.pdf", 1