跳轉到

隱寫術引擎

SteganographyEngine 提供在 PDF 文件中嵌入與萃取隱藏資料的能力,視覺上不可見,不影響文件正常使用,但可在任何時刻提取出預先嵌入的識別資訊。

典型用途:文件溯源追蹤、智慧財產保護、隱密浮水印(forensic watermarking)、隱密通道通訊。


嵌入技術

技術 說明 隱蔽性 容量 抗壓縮
LSB 圖像隱寫 修改圖像像素最低有效位
DCT 係數修改 修改 JPEG DCT 係數
字元間距編碼 微調文字字元間距(±0.001 pt) 極高
行間距編碼 微調段落行間距 極高
PDF 物件流嵌入 在物件流中嵌入隱藏資料
不可見注釋層 白色注釋層嵌入資料
中繼資料隱寫 XMP 自定義命名空間隱藏欄位

核心 API

SteganographyEngine

use NextPDF\Enterprise\Security\Steganography\SteganographyEngine;
use NextPDF\Enterprise\Security\Steganography\EmbedConfig;
use NextPDF\Enterprise\Security\Steganography\EmbedTechnique;
use NextPDF\Enterprise\Security\Steganography\SecretPayload;

$engine = new SteganographyEngine(
    encryptionKey: $aes256Key, // 嵌入前加密 payload
);

// 嵌入隱藏資料
$payload = SecretPayload::create(
    data: json_encode([
        'document_id' => 'RPT-2025-Q4-001',
        'recipient_id' => 'CLIENT-ACME-001',
        'issued_at' => '2025-01-15T09:00:00Z',
        'classification' => 'CONFIDENTIAL',
    ]),
    encoding: PayloadEncoding::Json,
);

$config = EmbedConfig::create()
    ->useTechnique(EmbedTechnique::TextSpacingWithDct)  // 結合字元間距 + DCT
    ->withRedundancy(redundancyCopies: 3)               // 冗餘嵌入以防內容遮蔽
    ->withIntegrityHmac()                               // HMAC-SHA-256 完整性保護
    ->withCapacityGuard();                              // 超過容量時拋出例外

$markedDocument = $engine->embed(
    document: $originalPdfBytes,
    payload: $payload,
    config: $config,
);

PHP Compatibility

This example uses PHP 8.5 syntax. If your environment runs PHP 8.1 or 7.4, use NextPDF Backport for a backward-compatible build.

SteganographyExtractor

use NextPDF\Enterprise\Security\Steganography\SteganographyExtractor;

$extractor = new SteganographyExtractor(
    decryptionKey: $aes256Key,
);

$result = $extractor->extract($markedPdfBytes);

if ($result->hasPayload()) {
    $payload = $result->payload();
    echo $payload->data();              // 解密後的原始資料
    echo $payload->encoding()->name;    // JSON | BINARY | TEXT

    // 完整性驗證
    if (!$result->isIntegrityVerified()) {
        // Payload 遭竄改
        $alertService->reportTampering($result->documentHash());
    }
} else {
    echo '未偵測到隱藏 payload(或解密金鑰錯誤)';
}

文件溯源(Forensic Watermarking)

溯源浮水印為每位收件人產生獨特的標記版本,當文件外洩時可識別洩漏來源:

use NextPDF\Enterprise\Security\Steganography\ProvenanceWatermarker;
use NextPDF\Enterprise\Security\Steganography\RecipientToken;

$watermarker = new ProvenanceWatermarker(
    engine: $steganographyEngine,
    tokenRegistry: $tokenRegistry, // 儲存 token → recipient 對應
);

// 為每位收件人產生獨特版本
$recipients = [
    RecipientToken::create('CLIENT-ACME-001', 'ACME Corporation'),
    RecipientToken::create('CLIENT-BETA-002', 'Beta Industries'),
    RecipientToken::create('EMPLOYEE-0042', 'John Chen'),
];

$markedVersions = $watermarker->watermarkForRecipients(
    sourceDocument: $confidentialReport,
    recipients: $recipients,
    includeDistributionLog: true,
);

// 稽核分發記錄
$log = $markedVersions->distributionLog();
// $log 記錄:誰、何時、收到哪個版本

溯源調查

use NextPDF\Enterprise\Security\Steganography\LeakInvestigator;

$investigator = new LeakInvestigator(
    extractor: $extractor,
    tokenRegistry: $tokenRegistry,
);

// 從外洩文件萃取識別資訊
$finding = $investigator->investigate($suspectedLeakedPdfBytes);

if ($finding->hasIdentification()) {
    echo '洩漏來源:' . $finding->recipient()->name();
    echo '文件版本:' . $finding->token()->value();
    echo '原始分發時間:' . $finding->distributedAt()?->format('c');
    echo '信賴度:' . $finding->confidence() . '%';
}

加密保護

所有嵌入的 payload 均使用 AES-256-GCM 加密,防止對手直接讀取:

use NextPDF\Enterprise\Security\Steganography\PayloadCrypto;

$crypto = PayloadCrypto::create(
    algorithm: 'AES-256-GCM',
    keyDerivation: 'HKDF-SHA-256',
    masterKey: $masterKey,
    context: 'nextpdf-stego-v1',
);

$engine = new SteganographyEngine(crypto: $crypto);

效能規格

場景 指標
嵌入(10 頁,文字間距技術)
嵌入(10 頁,DCT 技術)
萃取(10 頁)
批次浮水印(100 份收件人版本)

延伸閱讀