|
THotPDF.SignPDFWithPFX
|
ก่อนหน้า เมธอด 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;
คำอธิบาย
1. โหลด input PDF หา sentinel placeholders 2. โหลด PFX file และ decrypt ด้วย password ที่ให้มา รองรับ PBES2 with PBKDF2-HMAC-SHA-256 + AES-256-CBC ซึ่งเป็น default สำหรับ PFX files ที่ export โดย OpenSSL 3.0+, Windows 11+ 3. คำนวณ SHA-256 เหนือ document bytes ที่ 4. hex-encode CMS DER ตรวจสอบว่าใส่ใน 5. Writes the patched bytes to the output path or stream.
Returns True on success. Raises
Typical workflow
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');
Notes signature algorithm คือ RSA + SHA-256 (
สำหรับ PAdES B-T / B-LT / B-LTA workflows ที่ต้องใช้ RFC 3161 timestamps, DSS dictionaries, หรือ document timestamp signatures ให้ใช้ producer-side helpers (
See also: AddSignedSignatureField, PreparePDFForSigning, InsertSignatureHex, AddPAdESSignatureField |