THotPDF.SignPDFWithPFX

THotPDF

 

Prethodno  Metode  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;

 

Opis

SignPDFWithPFX je end-to-end PFX signing ulazna tačka dodata u v2.119.27 Ulazni PDF već mora da sadrži placeholder za potpis emitovan od strane THPDFPage.AddSignedSignatureField (ili njegovog PAdES omotača) sa subFilter adbe.pkcs7.detached Metod:

 

1. Učitava ulazni PDF, pronalazi /ByteRange + /Contents sentinel placeholder-e i zakrpljuje /ByteRange stvarnim byte offset-ovima

2. Učitava PFX fajl i dešifruje ga prosleđenom lozinkom. Podržan je PBES2 sa PBKDF2-HMAC-SHA-256 + AES-256-CBC (ovo je podrazumevano za PFX fajlove izvezene iz OpenSSL 3.0+, Windows 11+ certutil i macOS Keychain Access). Legacy PBE-SHA1-3DES fajlovi prijavljuju dijagnostiku; ponovo ih izvezite sa openssl pkcs12 -export ... -keypbe AES-256-CBC -certpbe AES-256-CBC

3. Računa SHA-256 nad /ByteRange-covered bajtovima dokumenta i gradi CMS SignedData (RFC 5652) DER blob koji sadrži X.509 sertifikat, potpisane atribute (contentType + messageDigest + signingTime) i RSA + SHA-256 potpis nad SET-tagged potpisanim atributima

4. Hex-enkodira CMS DER, proverava da li staje u /Contents budžet rezervisan od strane AddSignedSignatureField (podrazumevano 8 KB pokriva 1024 / 2048-bit RSA) i ubacuje ga u placeholder

5. Upisuje zakrpljene bajtove u izlaznu putanju ili tok

 

Returns True on success. Raises EHPDFPFXError on a bad password, unsupported encryption profile, or malformed PFX; EHPDFCMSError when the input PDF lacks the expected placeholder or the CMS DER overflows the reserved /Contents budget; EHPDFRSAError on RSA key mismatch.

 

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 sertifikata. encapContentInfo je odvojen (eContent je izostavljen). Potpisani atributi se sortiraju uzlazno po DER bajt-nizu prema RFC 5652 §5.4 pre heširanja

 

Za PAdES B-T / B-LT / B-LTA tokove rada kojima su potrebni RFC 3161 timestampovi, DSS rečnici ili document timestamp potpisi, pomoćnici na strani proizvođača (AddPAdESSignatureField, AddPAdESDSSCertificate, AddDocumentTimestampSignature) i dalje važe; SignPDFWithPFX sam po sebi emituje osnovni CMS-only potpis (PAdES-B-B ekvivalent)

 

See also: AddSignedSignatureField, PreparePDFForSigning, InsertSignatureHex, AddPAdESSignatureField