Skip to content

Chữ ký số PAdES

Pro — Commercial License Required
Cấp chữ ký PAdES B-T, B-LT và B-LTA yêu cầu package Pro.

TCPDF-Next Pro implement pipeline PAdES đầy đủ (ETSI EN 319 142) dùng CertificateInfo, DigitalSigner, ByteRangeCalculatorSignatureAppearance.

Cấp chữ ký

CấpGiá trị EnumThêm gì
B-BSignatureLevel::PAdES_B_BChữ ký CMS với chứng chỉ ký
B-TSignatureLevel::PAdES_B_TRFC 3161 signature timestamp
B-LTSignatureLevel::PAdES_B_LTDữ liệu thu hồi (OCSP + CRL) qua DSS
B-LTASignatureLevel::PAdES_B_LTADocument timestamp cho hiệu lực vô thời hạn

CertificateInfo

Tải và parse chứng chỉ X.509 và private key từ file PEM hoặc PKCS#12.

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

// Từ file PEM
$cert = CertificateInfo::fromPem('/certs/signing.pem', '/certs/signing.key', 'pw');
$cert->chain(['/certs/intermediate.pem', '/certs/root.pem']);

// Từ PKCS#12 (chain trích xuất tự động)
$cert = CertificateInfo::fromPkcs12('/certs/signing.p12', 'p12-password');

// Kiểm tra chi tiết chứng chỉ
echo $cert->subjectCN();        // "John Doe"
echo $cert->issuerCN();         // "Acme Intermediate CA"
echo $cert->validFrom();        // DateTimeImmutable
echo $cert->ocspResponderUrl(); // "https://ocsp.acme.com"

DigitalSigner

Tạo container chữ ký CMS/PKCS#7 và điều phối nhúng timestamp và LTV.

php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\Pro\Security\Signature\DigitalSigner;
use Yeeefang\TcpdfNext\Pro\Security\Timestamp\TsaClient;
use Yeeefang\TcpdfNext\Contracts\Enums\SignatureLevel;

$pdf  = Document::create()->addPage()->text('Contract document.');
$cert = CertificateInfo::fromPkcs12('/certs/signer.p12', 'pw');
$tsa  = new TsaClient('https://tsa.example.com/timestamp');

$signer = new DigitalSigner($cert);
$signer->level(SignatureLevel::PAdES_B_LTA);
$signer->timestampAuthority($tsa);
$signer->reason('Document approval');
$signer->location('Taipei, Taiwan');

$signer->sign($pdf);
$pdf->save('/output/signed.pdf');

Tại cấp B-LT và B-LTA, LtvManager được gọi nội bộ để tải OCSP response và CRL rồi xây dựng dictionary DSS.

ByteRangeCalculator

Quản lý placeholder chữ ký và tính byte range. Được xử lý nội bộ bởi DigitalSigner; dùng trực tiếp cho tình huống nâng cao.

SignatureAppearance

Kiểm soát biểu diễn hiển thị của chữ ký trên trang. Chữ ký mặc định ẩn.

php
use Yeeefang\TcpdfNext\Pro\Security\Signature\SignatureAppearance;

$appearance = SignatureAppearance::create()
    ->page(1)
    ->position(x: 20.0, y: 250.0, width: 80.0, height: 30.0)
    ->text("Digitally signed by John Doe\nDate: 2026-02-16")
    ->image('/images/handwritten-signature.png')
    ->imagePosition('left')  // 'left', 'right', 'top', 'bottom', 'background'
    ->fontSize(8);

$signer->appearance($appearance);
$signer->sign($pdf);

Ví dụ B-LTA đầy đủ

php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\Pro\Security\Signature\{DigitalSigner, CertificateInfo, SignatureAppearance};
use Yeeefang\TcpdfNext\Pro\Security\Timestamp\TsaClient;
use Yeeefang\TcpdfNext\Contracts\Enums\SignatureLevel;

$pdf = Document::create()
    ->addPage()
    ->font('Helvetica', size: 14, style: 'B')
    ->text('Purchase Agreement')
    ->font('Helvetica', size: 11)
    ->text('This agreement is entered into on February 16, 2026...');

$cert = CertificateInfo::fromPkcs12('/certs/legal.p12', 'passphrase');
$tsa  = new TsaClient('https://tsa.example.com/timestamp');

$signer = new DigitalSigner($cert);
$signer->level(SignatureLevel::PAdES_B_LTA);
$signer->timestampAuthority($tsa);
$signer->appearance(
    SignatureAppearance::create()
        ->page(1)
        ->position(x: 20.0, y: 250.0, width: 80.0, height: 25.0)
        ->text("Signed by Legal Dept.\n2026-02-16")
);
$signer->reason('Purchase agreement execution');
$signer->location('Taipei, Taiwan');

$signer->sign($pdf);
$pdf->save('/contracts/purchase-agreement-signed.pdf');

Bước tiếp theo

Phân phối theo giấy phép LGPL-3.0-or-later.