|
THotPDF.SignPDFWithPFX
|
Önceki Yöntemler AddPubKeyRecipient |
|
Signs an existing PDF placeholder using a PFX / PKCS#12 file, building a CMS SignedData container and writing the signed PDF in one call.
Delphi syntax (file overload): class function SignPDFWithPFX( const InputPDFPath: string; const OutputPDFPath: string; const PFXFilePath: string; const Password: AnsiString): boolean; overload; static;
Delphi syntax (stream overload): class function SignPDFWithPFX( InputStream: TStream; OutputStream: TStream; const PFXFilePath: string; const Password: AnsiString): boolean; overload; static;
Açıklama
1. Girdi PDF dosyasını yükler, /ByteRange + /Contents sentinel placeholderlarını bulur ve /ByteRange alanını gerçek byte offsets ile patchler 2. PFX dosyasını yükler ve sağlanan parola ile çözer. PBES2 with PBKDF2-HMAC-SHA-256 + AES-256-CBC desteklenir (OpenSSL 3.0+, Windows 11+ certutil ve macOS Keychain Access tarafından dışa aktarılan PFX dosyaları için varsayılan budur). Legacy PBE-SHA1-3DES files diagnostic üretir; 3. /ByteRange tarafından kapsanan document bytes üzerinde SHA-256 hesaplar ve X.509 certificate, signed attributes (contentType + messageDigest + signingTime) ve SET-tagged signed attributes üzerinde RSA + SHA-256 imzası içeren bir CMS SignedData (RFC 5652) DER blob oluşturur 4. CMS DER içeriğini hex olarak kodlar, AddSignedSignatureField tarafından ayrılan /Contents bütçesine sığdığını doğrular (varsayılan 8 KB, 1024 / 2048-bit RSA için yeterlidir) ve placeholder içine enjekte eder 5. Patched bytes içeriğini çıktı yoluna veya stream içine yazar
Başarı durumunda True döndürür. Hatalı parola, desteklenmeyen encryption profile veya malformed PFX için
Tipik iş akışı
Doc := THotPDF.Create(nil); Doc.FileName := 'unsigned.pdf'; Doc.BeginDoc; Doc.CurrentPage.AddSignedSignatureField( 'Sig1', Rect(60, 60, 260, 90), 8192, 'adbe.pkcs7.detached', 'Approved', 'Brussels', '', []); Doc.EndDoc; Doc.Free; THotPDF.SignPDFWithPFX('unsigned.pdf', 'signed.pdf', 'mykey.pfx', 'mypassword');
Notlar İmza algoritması RSA + SHA-256 (1.2.840.113549.1.1.1 + 2.16.840.1.101.3.4.2.1) şeklindedir. Signer identifier, X.509 certificate içinden çıkarılan IssuerAndSerialNumber değeridir. encapContentInfo detached durumdadır (eContent atlanır). Signed attributes, hash edilmeden önce RFC 5652 §5.4 uyarınca artan DER byte string sırasına göre sıralanır
RFC 3161 timestamps, DSS dictionaries veya document timestamp signatures gerektiren PAdES B-T / B-LT / B-LTA workflows için producer-side helpers (AddPAdESSignatureField, AddPAdESDSSCertificate, AddDocumentTimestampSignature) hâlâ geçerlidir; SignPDFWithPFX kendisi temel bir CMS-only signature üretir (PAdES-B-B eşdeğeri)
Ayrıca bkz.: AddSignedSignatureField, PreparePDFForSigning, InsertSignatureHex, AddPAdESSignatureField |