PDFium Delphi Component Docs

FPdfEncrypt الوحدة

الوحدة: FPdfEncrypt
يشتق مفاتيح تعمية AES-256 ويصدر سلاسل وتيارات وقواميس تعمية AESV3-CBC وفق ISO 32000-2 أو AESV4-GCM وفق ISO/TS 32003

الصياغة

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 الموجود
TPdfMacValidationStatuspmvsValid أو pmvsNotPresent أو pmvsInvalid أو pmvsUnsupported
TPdfMacValidationResultStatus للتحقق من PDF MAC المستقل و MessageText التشخيصية

ملاحظات

انظر أيضًا

FPdfAes, FPdfSha256, FPdfHmac, FPdfMac, TPdf.SaveAsEncrypted, TPdf.SaveAsEncryptedToStream