DAOpenFileWithEncryptionKey
Document management, Direct access functionality, Security
Description
Opens an encrypted PDF for authorised recovery or investigation by accepting the hexadecimal file-encryption key directly instead of deriving it from a password
The file is opened through a source-read-only handle and cannot be appended to in place
Syntax
Delphi
Function TPDFlib.DAOpenFileWithEncryptionKey(Const InputFileName, EncryptionKeyHex: WideString; Options: Integer = 0): Integer;ActiveX
Function PDFlib::DAOpenFileWithEncryptionKey(InputFileName As String, EncryptionKeyHex As String, Options As Long) As Long
Available on IPDFlibrary5 from type library version 3.6
DLL
int DLDAOpenFileWithEncryptionKey(int InstanceID, const wchar_t* InputFileName, const wchar_t* EncryptionKeyHex, int Options);
int DLDAOpenFileWithEncryptionKeyA(int InstanceID, const char* InputFileName, const char* EncryptionKeyHex, int Options);Parameters
| InputFileName | The path and name of the encrypted PDF |
|---|---|
| EncryptionKeyHex | An even-length ASCII hexadecimal key with no prefix or whitespace; revisions 2 to 4 require the exact key length declared by the encryption dictionary and revisions 5 to 7 require 32 bytes |
| Options | Zero requires an available verifier; PDF_RAW_KEY_ALLOW_UNVERIFIED permits an otherwise valid key only when the document has no usable verifier |
Return values
| Non-zero | A Direct Access file handle |
|---|---|
| 0 | The input could not be opened; inspect LastErrorCode, including PDFLIB_ERROR_RAW_ENCRYPTION_KEY_INVALID for invalid syntax, length, options or verification |
Remarks
Available revision 2 to 4 /U values and revision 5 to 7 /Perms values are always checked; PDF_RAW_KEY_ALLOW_UNVERIFIED never accepts a mismatch
Supported public-key PDFs with a single encrypted filter or a legacy document-wide key can be opened with their file-encryption key and PDF_RAW_KEY_ALLOW_UNVERIFIED. The handle reports an unverified key because public-key encryption has no standard password-key verifier
For a public-key PDF with multiple encrypted filters, configure a PFX credential or a certificate store and call DAOpenFileReadOnly
Call DAGetEncryptionKeyValidation after opening to distinguish verified and explicitly unverified handles
The key is sensitive credential material and should be obtained, transported and stored under the same controls as a document password