Skip to content

Firme Digitali (HasSecurity)

Il trait HasSecurity fornisce setSignature() per firme digitali conformi PAdES. TCPDF-Next supporta quattro livelli firma — da base (B-B) ad archivio (B-LTA) — tramite PadesOrchestrator, TsaClient e moduli LTV. Tutti i metodi firma restituiscono static per concatenazione.

Riferimento Rapido

Classe / EnumScopo
CertificateInfoCarica certificati firma (PEM o PKCS#12)
SignatureLevelEnum: PAdES_B_B, PAdES_B_T, PAdES_B_LT, PAdES_B_LTA
TsaClientClient autorità timestamp RFC 3161
SignatureAppearanceWidget firma visibile o invisibile
OcspClientControllo revoca online RFC 6960
CrlFetcherFetch punto distribuzione CRL RFC 5280

Livelli Firma

LivelloCosa IncludeValidità
B-B (Base)Firma + certificato firmaValida mentre certificato non è revocato
B-T (Timestamp)B-B + timestamp RFC 3161Prova firma esisteva prima di un punto nel tempo
B-LT (Long-Term)B-T + DSS con risposte OCSP/CRLVerificabile dopo scadenza certificato
B-LTA (Archivio)B-LT + timestamp documento + loop archivioVerificabile indefinitamente

Ciclo Vita Firma PAdES

Caricamento Certificati

Da File PEM

php
use Yeeefang\TcpdfNext\Security\Signature\CertificateInfo;

$cert = CertificateInfo::fromFiles(
    certPath: '/path/to/certificate.pem',
    keyPath: '/path/to/private-key.pem',
    password: 'key-password',
    extraCerts: '/path/to/ca-chain.pem',  // certificati intermedi opzionali
);

Da PKCS#12 (.p12 / .pfx)

php
use Yeeefang\TcpdfNext\Security\Signature\CertificateInfo;

$cert = CertificateInfo::fromPkcs12(
    p12Path: '/path/to/certificate.p12',
    password: 'pkcs12-password',
);

Esempi Firma

php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\Security\Signature\CertificateInfo;
use Yeeefang\TcpdfNext\Contracts\SignatureLevel;
use Yeeefang\TcpdfNext\Security\Timestamp\TsaClient;

$cert = CertificateInfo::fromFiles(
    certPath: '/path/to/certificate.pem',
    keyPath: '/path/to/private-key.pem',
    password: 'key-password',
);

// PAdES B-B (Base) — solo firma
$pdf = Document::create()
    ->setSignature($cert, SignatureLevel::PAdES_B_B)
    ->addPage()
    ->setFont('Helvetica', '', 12)
    ->cell(0, 10, 'Signed document (B-B)')
    ->save('signed-bb.pdf');

// PAdES B-T (Timestamp) — firma + timestamp
$tsa = new TsaClient('https://freetsa.org/tsr');
$pdf = Document::create()
    ->setSignature($cert, SignatureLevel::PAdES_B_T, $tsa)
    ->addPage()
    ->cell(0, 10, 'Signed + timestamped')
    ->save('signed-bt.pdf');

Rilasciato sotto licenza LGPL-3.0-or-later.