TPdfEncryptionRevision = (erR5, erR6, erR7);
TPdfEncryptOptions = record
UserPassword: AnsiString;
OwnerPassword: AnsiString;
Permissions: Cardinal;
EncryptMetadata: Boolean;
Revision: TPdfEncryptionRevision;
EnableIntegrityProtection: Boolean;
class function Default: TPdfEncryptOptions; static;
end;
TPdfEncryptionKeys = record
FileEncryptionKey: TBytes;
OEntry: TBytes;
UEntry: TBytes;
OEEntry: TBytes;
UEEntry: TBytes;
PermsEntry: TBytes;
KdfSalt: TBytes;
end;
TPdfIncrementalEncryptionContext = record
FileEncryptionKey: TBytes;
KdfSalt: TBytes;
Revision: TPdfEncryptionRevision;
EncryptMetadata: Boolean;
EncryptObjectNumber: Integer;
EncryptGeneration: Integer;
HasAuthenticationCode: Boolean;
end;
procedure DeriveEncryptionKeys(const Options: TPdfEncryptOptions;
out Keys: TPdfEncryptionKeys);
function BuildEncryptDictionary(const Keys: TPdfEncryptionKeys;
const Options: TPdfEncryptOptions): AnsiString;
function EncryptStreamPayload(const FileKey: TBytes;
const Plain: TBytes): TBytes;
function EncryptDocumentBytes(const PlainPdf: TBytes;
const Options: TPdfEncryptOptions): TBytes;
function DecryptAesGcmDocumentBytes(const EncryptedPdf: TBytes;
const Password: AnsiString; out PlainPdf: TBytes;
out ErrorText: string): Boolean;
function ValidateEncryptedDocumentMac(const EncryptedPdf: TBytes;
const Password: AnsiString): TPdfMacValidationResult;
function ReadIncrementalEncryptionContext(const EncryptedPdf: TBytes;
const Password: AnsiString;
out Context: TPdfIncrementalEncryptionContext;
out ErrorText: string): Boolean;
procedure ClearIncrementalEncryptionContext(
var Context: TPdfIncrementalEncryptionContext);
function EncryptIncrementalObjectBody(const PlainBody: TBytes;
const Context: TPdfIncrementalEncryptionContext;
out EncryptedBody: TBytes;
out ErrorText: string): Boolean;
ينفذ FPdfEncrypt معالج أمان PDF بـ AES-256 المعرف في القسم 7.6 من ISO 32000-2 وامتداد AESV4-GCM المعرف في ISO/TS 32003. يحول EncryptDocumentBytes مصفوفة بايتات PDF صريحة إلى مستند معمَّى بالمراجعة المنتقاة
يشغّل DeriveEncryptionKeys اشتقاق المفاتيح القائم على كلمة السر الذي ينتج مفتاح تعمية الملف بطول 32 بايتًا مع إدخالات القاموس /O و /U و /OE و /UE و /Perms. يسلسل BuildEncryptDictionary تلك الإدخالات في نص قاموس /Encrypt. يطبق EncryptStreamPayload تعمية AES-256-CBC على تيار كائن واحد باستخدام مفتاح الملف
يستطيع المستخدم المتقدم الباني لمسار حفظ مخصص استدعاء البدائيات الثلاث مباشرة؛ وتستخدم شيفرات التطبيقات عادةً TPdf.SaveAsEncrypted أو TPdf.SaveAsEncryptedToStream اللذين يستدعيان EncryptDocumentBytes داخليًا
عندما تكون EnableIntegrityProtection صحيحة، يصدر الكاتب رمز مصادقة PDF 2.0 مستقلًا وفق ISO/TS 32004 مع /ByteRange تام يغطي EOF و /KDFSalt و CMS AuthenticatedData و HKDF-SHA256 و AES-256 Key Wrap و HMAC-SHA256
لا يكشف PDFium حاليًا تحليل AESV4 عبر ABI العام الخاص به. استدعِ DecryptAesGcmDocumentBytes أولًا ومرر البايتات المُعادة إلى TPdf.LoadDocument؛ ولا تعيد الدالة أي نص صريح جزئي بعد فشل كلمة سر أو صلاحية أو PDF MAC أو وسم سلسلة أو وسم تيار
يصادق ReadIncrementalEncryptionContext على سلسلة المراجعات المعمَّاة الحالية ويسترجع حالة الأمان الموروثة. يعمي EncryptIncrementalObjectBody السلاسل وحمل التيار في كائن غير مباشر متغير واحد مع حفظ استثناءات البيانات الوصفية وتحديث قيم /Length المباشرة؛ ويمسح ClearIncrementalEncryptionContext مواد المفاتيح المسترجعة
| الدالة | الوصف |
|---|---|
DeriveEncryptionKeys | يشغّل اشتقاق المفاتيح القائم على كلمة السر ويعيد مفتاح الملف وإدخالات القاموس الخمسة |
BuildEncryptDictionary | يسلسل المفاتيح والخيارات في نص قاموس /Encrypt |
EncryptStreamPayload | يعمي تيار كائن واحدًا بـ AES-256-CBC باستخدام مفتاح الملف |
EncryptDocumentBytes | مساعد لمرة واحدة يشتق المفاتيح ويعيد كتابة التيارات ويحقن قاموس /Encrypt في مصفوفة بايتات PDF كاملة |
DecryptAesGcmDocumentBytes | يصادق ويفك تعمية مخرجات AESV4-GCM إلى بايتات نص صريح يستطيع PDFium تحميلها |
ValidateEncryptedDocumentMac | يتحقق من PDF MAC مستقل مقابل البايتات المعمَّاة الأصلية باستخدام كلمة سر مستخدم أو مالك |
ReadIncrementalEncryptionContext | يصادق على سلسلة مراجعات معمَّاة ويسترجع مفتاح الملف الموروث والمراجعة وسياسة البيانات الوصفية ومرجع /Encrypt وحالة PDF MAC |
ClearIncrementalEncryptionContext | يمسح بأمان مواد مفاتيح التعمية التزايدية المسترجعة |
EncryptIncrementalObjectBody | يعمي السلاسل والتيارات في جسم كائن غير مباشر متغير واحد تحت سياق الأمان الموروث |
| النوع | الوصف |
|---|---|
TPdfEncryptionRevision | تعداد ينتقي مراجعة AESV3-CBC بقيمة erR5 أو erR6، أو مراجعة AESV4-GCM وفق ISO/TS 32003 بقيمة erR7 |
TPdfEncryptOptions | سجل يحمل كلمات السر وعلامات الصلاحيات وسياسة البيانات الوصفية ومراجعة معالج الأمان وحماية سلامة PDF MAC الاختيارية |
TPdfEncryptionKeys | سجل يحمل مفتاح الملف وإدخالات معالج الأمان و /KDFSalt الاختياري بطول 32 بايتًا |
TPdfIncrementalEncryptionContext | حالة أمان موروثة مُصادَق عليها تستخدم لإلحاق كائنات غير مباشرة معمَّاة دون استبدال قاموس /Encrypt الموجود |
TPdfMacValidationStatus | pmvsValid أو pmvsNotPresent أو pmvsInvalid أو pmvsUnsupported |
TPdfMacValidationResult | Status للتحقق من PDF MAC المستقل و MessageText التشخيصية |
DecryptAesGcmDocumentBytes سلاسل مراجعات /Prev الكلاسيكية التي يصدرها الكاتب التزايدي المعمَّى ويحل أحدث جيل كائن نشط؛ وتحميل AESV4 الأصلي في PDFium وإدخال AESV4 عبر xref-stream خارجي غير متاحين في هذا الإصدارPermissions تخطيط بتات الجدول 22 من ISO 32000-1 (علامات /P)