數位簽章¶
NextPDF 實作 PAdES B-B(PDF Advanced Electronic Signatures Baseline B,ETSI EN 319 142-1)數位簽章標準。PadesOrchestrator 協調整個簽章流程:從預留 ByteRange 空間、計算文件雜湊值,到生成符合標準的 CMS SignedData 結構。
基本簽章¶
use NextPDF\Security\PadesOrchestrator;
use NextPDF\Security\SigningCertificate;
use NextPDF\Security\SigningOptions;
$orchestrator = PadesOrchestrator::create();
// 載入簽章憑證
$cert = SigningCertificate::fromPkcs12(
path: '/path/to/certificate.p12',
password: 'cert-password',
);
// 簽署文件
$signedPdf = $orchestrator->sign(
pdf: $document->finalize(),
certificate: $cert,
options: SigningOptions::create(
level: SignatureLevel::PadesB_B, // B-B | B-T | B-LT | B-LTA
reason: 'Document Approval',
location: 'Taipei, Taiwan',
contactInfo: 'signer@example.com',
),
);
PAdES 等級¶
| 等級 | 說明 | 要求 |
|---|---|---|
B-B | Baseline B | 憑證 + CMS SignedData(Core 支援) |
B-T | Baseline T | B-B + 可信時間戳記(Core 支援) |
B-LT | Baseline LT | B-T + 憑證鏈 + 撤銷資訊(Pro 套件) |
B-LTA | Baseline LTA | B-LT + 歸檔時間戳記(Pro 套件) |
CMS SignedData 結構¶
PAdES B-B 使用 CMS(Cryptographic Message Syntax,RFC 5652)SignedData 格式封裝簽章:
SignedData {
version: 1
digestAlgorithms: [SHA-256]
encapContentInfo: {
eContentType: id-data (不含內容,使用 detached 模式)
}
certificates: [簽章憑證 + 中繼憑證鏈]
signerInfos: [{
version: 1
sid: IssuerAndSerialNumber
digestAlgorithm: SHA-256
signedAttrs: [
ContentType, MessageDigest, SigningTime,
SigningCertificateV2 (ESS)
]
signatureAlgorithm: RSA/ECDSA with SHA-256
signature: [簽章值]
}]
}
憑證鏈管理¶
use NextPDF\Security\CertificateChain;
// 手動指定中繼憑證
$cert = SigningCertificate::fromPem(
certificate: file_get_contents('/path/to/end-entity.pem'),
privateKey: file_get_contents('/path/to/private-key.pem'),
chain: CertificateChain::fromFiles([
'/path/to/intermediate-ca.pem',
'/path/to/root-ca.pem',
]),
);
視覺簽章外觀¶
use NextPDF\Security\VisualSignature;
use NextPDF\ValueObjects\Rectangle;
$options = SigningOptions::create(
level: SignatureLevel::PadesB_B,
visualSignature: VisualSignature::create(
pageNumber: 1,
position: Rectangle::fromXY(x: 100.0, y: 20.0, width: 70.0, height: 25.0),
image: '/path/to/signature-image.png',
showReason: true,
showDate: true,
showName: true,
),
);
簽章欄位¶
// 在特定的預留簽章欄位上簽章
$signedPdf = $orchestrator->sign(
pdf: $pdfBytes,
certificate: $cert,
options: SigningOptions::create(
fieldName: 'authorSignature', // 對應 AcroForm 中的簽章欄位名稱
),
);
參見¶
- 時間戳記 — RFC 3161 TSA 時間戳記
- 加密 — AES-256 加密
- AcroForm — 簽章欄位的建立
- Pro PAdES B-LTA — 長期有效性歸檔簽章