Encrypt

Security and Signatures

Description

This function adds the specified security settings to the selected document.

The actual encryption of the document is delayed until the document is saved so this function can be called at any time, even before further content is added to the document.

Syntax

Delphi

Function TPDFlib.Encrypt(Const Owner, User: WideString; Strength, Permissions: Integer): Integer;

ActiveX

Function PDFlib::Encrypt(Owner As String, User As String, Strength As Long, Permissions As Long) As Long

DLL

int DLEncrypt(int InstanceID, const wchar_t* Owner, const wchar_t* User, int Strength, int Permissions);
int DLEncryptA(int InstanceID, const char* Owner, const char* User, int Strength, int Permissions);

Parameters

OwnerThe owner or master password for the document
UserThe user password for the document
StrengthThe strength of encryption to use: 0 = 40-bit encryption 1 = 128-bit RC4 encryption 2 = 128-bit AES encryption (requires Acrobat 7 or later) 3 = 256-bit AES encryption (requires Acrobat 9 or later) 4 = 256-bit AES encryption (requires Acrobat X or later) 5 = 256-bit AES-GCM authenticated encryption (requires PDF 2.0 with ISO TS 32003) 6 = 128-bit SM4 CBC encryption (/CFM /SM4 as defined in GB/T 32907)
PermissionsA value created with the EncodePermissions function

Return values

0The document could not be encrypted. Use the LastErrorCode function to determine the reason for failure.
1The document was encrypted successfully

Remarks

Call SetPDFMACEnabled before this function to add a standalone PDF MAC integrity token when strength 4 or 5 is selected