|
THotPDF.SignPDFWithPFX
|
Prethodno Metode AddPubKeyRecipient |
|
Potpisuje postojeći PDF placeholder pomoću PFX / PKCS#12 datoteke, gradi CMS SignedData spremnik i zapisuje potpisani PDF jednim pozivom
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;
Opis SignPDFWithPFX je end-to-end PFX signing ulazna točka dodana u v2.119.27. Ulazni PDF već mora sadržavati signature placeholder ispisan od strane THPDFPage.AddSignedSignatureField (ili njegova PAdES omotača) s subFilter adbe.pkcs7.detached. Metoda:
1. Učitava ulazni PDF, pronalazi /ByteRange + /Contents sentinel placeholdera i zakrpava /ByteRange stvarnim byte offsetima 2. Učitava PFX datoteku i dekriptira je zadatom lozinkom. Podržan je PBES2 s PBKDF2-HMAC-SHA-256 + AES-256-CBC (to je zadano za PFX datoteke izvezene iz OpenSSL 3.0+, Windows 11+ certutila i macOS Keychain Accessa). Legacy PBE-SHA1-3DES datoteke podižu dijagnostiku; ponovno izvezite s openssl pkcs12 -export ... -keypbe AES-256-CBC -certpbe AES-256-CBC 3. Računa SHA-256 nad /ByteRange-obuhvaćenim byteovima dokumenta i gradi CMS SignedData (RFC 5652) DER blob koji sadrži X.509 certifikat, signed attributes (contentType + messageDigest + signingTime) i RSA + SHA-256 potpis nad SET-tagged signed attributes 4. CMS DER kodira u hex, provjerava da stane u /Contents budžet rezerviran od AddSignedSignatureField (zadano 8 KB pokriva 1024 / 2048-bit RSA) i ubacuje ga u placeholder 5. Zapisuje zakrpane bajtove na izlaznu putanju ili u tok
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 Algoritam potpisa je RSA + SHA-256 (1.2.840.113549.1.1.1 + 2.16.840.1.101.3.4.2.1) Identifikator potpisnika je IssuerAndSerialNumber izdvojen iz X.509 certifikata encapContentInfo je detached (eContent izostavljen) Potpisani atributi sortiraju se uzlazno po DER bajt stringu prema RFC 5652 §5.4 prije heširanja
Za PAdES B-T / B-LT / B-LTA radne tokove koji trebaju RFC 3161 vremenske oznake, DSS rječnike ili potpis dokumenta s vremenskom oznakom, i dalje vrijede pomoćne funkcije na strani proizvođača (AddPAdESSignatureField, AddPAdESDSSCertificate, AddDocumentTimestampSignature); sam SignPDFWithPFX emitira osnovni CMS-only potpis (ekvivalent PAdES-B-B)
See also: AddSignedSignatureField, PreparePDFForSigning, InsertSignatureHex, AddPAdESSignatureField |