Skip to content

PAdES デジタル署名

Pro — Commercial License Required
PAdES B-T、B-LT、B-LTA署名レベルにはProパッケージが必要です。

TCPDF-Next Proは、CertificateInfoDigitalSignerByteRangeCalculatorSignatureAppearanceを使用して、完全なPAdESパイプライン(ETSI EN 319 142)を実装しています。

署名レベル

レベルEnum値追加される内容
B-BSignatureLevel::PAdES_B_B署名証明書付きCMS署名
B-TSignatureLevel::PAdES_B_TRFC 3161署名タイムスタンプ
B-LTSignatureLevel::PAdES_B_LTDSS経由の失効データ(OCSP + CRL)
B-LTASignatureLevel::PAdES_B_LTA無期限有効性のためのドキュメントタイムスタンプ

CertificateInfo

PEMまたはPKCS#12ファイルからX.509証明書と秘密鍵を読み込み、解析します。

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

// PEMファイルから
$cert = CertificateInfo::fromPem('/certs/signing.pem', '/certs/signing.key', 'pw');
$cert->chain(['/certs/intermediate.pem', '/certs/root.pem']);

// PKCS#12から(チェーンは自動的に抽出)
$cert = CertificateInfo::fromPkcs12('/certs/signing.p12', 'p12-password');

// 証明書の詳細を確認
echo $cert->subjectCN();        // "John Doe"
echo $cert->issuerCN();         // "Acme Intermediate CA"
echo $cert->validFrom();        // DateTimeImmutable
echo $cert->ocspResponderUrl(); // "https://ocsp.acme.com"

DigitalSigner

CMS/PKCS#7署名コンテナを生成し、タイムスタンプおよび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');

B-LTおよびB-LTAレベルでは、LtvManagerが内部的に呼び出され、OCSPレスポンスとCRLを取得してDSSディクショナリを構築します。

ByteRangeCalculator

署名プレースホルダを管理し、バイト範囲を計算します。DigitalSignerによって内部的に処理されます。直接使用は高度なシナリオ向けです。

SignatureAppearance

ページ上の署名の可視表現を制御します。署名はデフォルトで不可視です。

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);

完全なB-LTAサンプル

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');

次のステップ

  • 長期検証 -- DSS、OCSP、CRL、およびアーカイブタイムスタンプ。
  • HSM統合 -- PKCS#11によるハードウェアセキュリティモジュール署名。
  • Proパッケージ概要 -- 全モジュール一覧とライセンス情報。

LGPL-3.0-or-later ライセンスの下で公開されています。