EncryptFile
Security and Signatures
Description
Encrypts a file on disk and saves the results to a new file; the entire document does not have to be loaded into memory so this function can be used to encrypt huge documents
Syntax
Delphi
Function TPDFlib.EncryptFile(Const InputFileName, OutputFileName, Owner, User: WideString; Strength, Permissions: Integer): Integer;
ActiveX
Function PDFlib::EncryptFile(InputFileName As String, OutputFileName As String, Owner As String, User As String, Strength As Long, Permissions As Long) As Long
DLL
int DLEncryptFile(int InstanceID, const wchar_t* InputFileName, const wchar_t* OutputFileName, const wchar_t* Owner, const wchar_t* User, int Strength, int Permissions);
int DLEncryptFileA(int InstanceID, const char* InputFileName, const char* OutputFileName, const char* Owner, const char* User, int Strength, int Permissions);
Parameters
| InputFileName | The name of the file to encrypt |
|---|---|
| OutputFileName | The name of the destination file to create |
| Owner | The owner password to use for the encrypted file; this is sometimes called the "master" password or the "permissions" password and is needed to change the document |
| User | The user password to use for the encrypted file; this is sometimes called the "open" password and allows the user to open the document within the permitted operations |
| Strength | The strength of encryption to use: 0 = 40-bit RC4 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 per GB/T 32907) |
| Permissions | A value created with the EncodePermissions function |
Return values
| 0 | The file could not be encrypted; check the result of the LastErrorCode |
|---|---|
| 1 | The document was encrypted successfully |
Remarks
Call SetPDFMACEnabled first to add a standalone PDF MAC integrity token when strength 4 or 5 is selected