Privacy-First Document Watermarking, Tamper Detection & Cryptographic Provenance Toolkit in Pure Rust
Protect sensitive identity cards (KTP, Passports, Driver's Licenses), tax documents (NPWP), financial bank statements, invoices, and PDF contracts from identity fraud, unauthorized reuse, and automated AI inpainting.
Quick Start β’ Why DocSeal? β’ Architecture β’ CLI Usage β’ Rust API β’ Benchmarks β’ Security Model
Every day, millions of people upload copies of their identity documents (KTP / National IDs, Passports, NPWP, Driver's Licenses, and Bank Statements) for online services, job applications, banking, and fintech verifications.
When identity data leaks or is misused by rogue third parties, victims suffer identity theft, fraudulent loan applications (pinjaman online ilegal), and financial impersonation.
Traditional document protection fails because:
- β Simple text overlays are easily removed: Generic semi-transparent text is easily erased with Photoshop Generative Fill, Stable Diffusion inpainting, or threshold subtraction.
- β Fragile LSB Steganography fails under compression: Minor JPEG compression (WhatsApp, Telegram, email) destroys least-significant-bit watermarks.
- β Cloud watermarkers leak privacy: Online watermark tools upload unencrypted sensitive personal data to untrusted remote servers.
- β No proof of ownership: Visual watermarks alone cannot mathematically prove who issued the document or when it was modified.
| Feature | DocSeal | Traditional Watermark | LSB Steganography |
|---|---|---|---|
| Execution Environment | 100% Offline / Local CPU | Local or Cloud | Local |
| Visible Protection | Rotated Lattice + Contrast Inversion | Static grid (easily erased) | None |
| Invisible Signal | 2D Haar DWT + 8x8 DCT + QIM | None | 1-bit LSB (fragile) |
| Error Correction | Reed-Solomon |
None | None |
| Lossy JPEG Survival | Survives JPEG Q=75β90 | Degrades visually | Destroyed (< Q=95) |
| PDF Processing | Native Vector Streams (No Rasterization) | Rasterizes pages to images | Rasterizes |
| Cryptographic Provenance | Ed25519 Signatures + DID Keys | None | None |
| Data Privacy | Zero PII Embedded in Payloads | Often leaks names/IDs | Variable |
- Identity & KYC Protection:
- Adding purpose-bound watermarks to KTP (Indonesian National ID), Passports, SIM (Driver's License), and SSN cards (e.g.
"FOR BANK ACCOUNT OPENING ONLY - 2026-08-26").
- Adding purpose-bound watermarks to KTP (Indonesian National ID), Passports, SIM (Driver's License), and SSN cards (e.g.
- Tax & Financial Compliance:
- Watermarking NPWP (Tax ID Cards), SPT reports, electronic invoices, and bank statements.
- Enterprise & Legal Contracts:
- Signing and watermarking confidential NDAs, employment agreements, university diplomas, and audit certificates.
- Anti-Fraud & Fintech Verification:
- Automated server-side document provenance verification using high-throughput Rust subroutines (< 11ms latency).
INPUT DOCUMENT
(Raster Image / PDF)
β
βΌ
ββββββββββββββββββββββββ
β Document Analyzer β
β - Saliency & Edges β
β - Page MediaBox β
β - Dynamic Luminance β
ββββββββββββ¬ββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββββββ βββββββββββββββββββββ βββββββββββββββββββββ
β Visible Layer β β Invisible Layer β β Provenance Layer β
β - Rotated Latticeβ β - 2D DWT (Haar) β β - Ed25519 Signing β
β - Contrast-Aware β β - 8x8 Block DCT β β - SHA-256 / BLAKE3β
β - Non-Colliding β β - QIM Modulation β β - Signed Manifest β
β - Saliency Alpha β β - Reed-Solomon ECCβ β - DID Key Format β
ββββββββββ¬ββββββββββ βββββββββββ¬ββββββββββ βββββββββββ¬ββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β Format Assembler β
β (PNG / JPEG / PDF) β
βββββββββββββ¬ββββββββββββ
β
βΌ
PROTECTED DOCUMENT
The project is architected as a modular, decoupled Cargo workspace:
-
crates/watermark-core: Pure-Rust 2D Haar DWT, 8x8 DCT, QIM, Reed-Solomon
$(32, 16)$ $GF(2^8)$ , and Barker-13 sync. - crates/watermark-crypto: Ed25519 signing/verification, DID keys, canonical RFC 8785 JSON manifest serialization, and document hashing.
-
crates/watermark-layout: Saliency edge-density analysis and collision-free rotated-frame coordinate lattice
$(u, v)$ . - crates/watermark-image: Raster image processing engine (PNG, JPEG, WebP) with embedded TrueType font rendering.
- crates/watermark-pdf: Native vector PDF injector (without vector rasterization) and scanned raster XObject processor.
- crates/watermark-detect: Multi-tile extraction, majority voting, payload recovery, and provenance verification.
- crates/watermark-benchmark: Adversarial attack harness (JPEG, resize, crop, noise, print-scan, inpaint) and PSNR/SSIM evaluators.
-
cli/docseal: Production CLI binary (
protect,verify,benchmark,keygen).
git clone https://github.com/egagofur/DocSeal.git
cd DocSeal
cargo build --release -p docseal
# Binary available at target/release/docsealDownload the latest binaries for Linux, macOS (Apple Silicon / Intel), and Windows from the Releases page.
docseal keygen --output issuer_key.binOutput:
π Generated Ed25519 Issuer Keypair
Public DID Key: did:key:z6MkwSbVf5Lh...
Raw Private Key: 8a3b4...
Key written to: issuer_key.bin
docseal protect sample_ktp.png \
--text "FOR BANK VERIFICATION ONLY - 2026-08-26" \
--sign-key issuer_key.bin \
--output ktp_protected.png \
--manifest-out ktp_manifest.jsondocseal protect statement.pdf \
--text "FOR VISA APPLICATION ONLY" \
--sign-key issuer_key.bin \
--output statement_protected.pdfdocseal verify ktp_protected.png --public-key did:key:z6MkwSbVf5Lh...Output:
ββββββββββββββββββββββββββββββββββββββββββββββββββ
DOCSEAL VERIFICATION REPORT
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Status: β VERIFIED (EXACT MATCH)
Watermark ID: wm_54256b6e7ea5ead16e143a682aea933f
Recovery Rate: 100.0%
Tiles Decoded: 6/6
Confidence: 0.95
Bit Error Rate: 0.000
[ Cryptographic Provenance ]
Manifest Present: β Yes
Signature Valid: β Valid
Issuer: did:key:z6MkwSbVf5Lh...
Purpose: BANK_VERIFICATION
[ Document Integrity ]
SHA-256 Digest: sha256:7748ac35eabb8616a3f91c6e149b0def...
Integrity Status: EXACT_MATCH_UNMODIFIED
ββββββββββββββββββββββββββββββββββββββββββββββββββ
Add DocSeal crates to your Cargo.toml:
[dependencies]
watermark-image = { git = "https://github.com/egagofur/DocSeal.git" }
watermark-crypto = { git = "https://github.com/egagofur/DocSeal.git" }
watermark-detect = { git = "https://github.com/egagofur/DocSeal.git" }use watermark_crypto::IssuerKeypair;
use watermark_image::{ImageWatermarkEngine, ProtectImageOptions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let raw_bytes = std::fs::read("identity_card.png")?;
let keypair = IssuerKeypair::generate();
let options = ProtectImageOptions {
visible_text: Some("FOR LOAN VERIFICATION ONLY".to_string()),
secret_key: b"org_master_secret_seed".to_vec(),
document_id: b"doc_ref_9821".to_vec(),
purpose: "LOAN_APPLICATION".to_string(),
qim_delta: 36.0,
opacity: 0.20,
rotation_deg: 32.0,
enable_invisible: true,
enable_visible: true,
format: image::ImageFormat::Png,
..Default::default()
};
let result = ImageWatermarkEngine::protect(&raw_bytes, &options, Some(&keypair))?;
std::fs::write("protected_card.png", &result.image_bytes)?;
println!("Embedded Watermark ID: {}", result.watermark_id.to_prefixed_hex());
Ok(())
}All metrics represent real, reproducible measurements generated by the automated benchmark runner (docseal benchmark):
| Attack Scenario | Recovery Rate | BER | PSNR | SSIM | Detection Verdict |
|---|---|---|---|---|---|
| Baseline (Clean) | 100.0% | 0.000 | 29.42 dB | 0.8990 | β Verified |
| JPEG Quality = 90 | 100.0% | 0.026 | 28.93 dB | 0.8984 | β Verified |
| JPEG Quality = 75 | 83.3% | 0.203 | 28.59 dB | 0.8969 | β Verified |
| Downscale 75% | 33.3% | 0.365 | 27.04 dB | 0.8839 | β Partial Recovery |
| Downscale 50% | 16.7% | 0.438 | 24.70 dB | 0.8612 | β Partial Recovery |
| Border Crop 10% | 33.3% | 0.401 | 15.66 dB | 0.8515 | β Partial Recovery |
| Print-Scan Simulation | 33.3% | 0.359 | 27.85 dB | 0.8234 | β Partial Recovery |
- 1080p Image Protection:
135.4 ms - 1080p Image Verification:
10.4 ms - 4K UHD Image Verification:
46.8 ms - Vector PDF Verification:
1.2 ms
See BENCHMARKS.md for the full attack analysis.
Important
Honest Engineering Boundaries:
No watermarking system can guarantee that an analog or raster document cannot be recreated or modified by an adversary with infinite contextual knowledge. DocSeal is engineered to make unauthorized reuse, automated mass extraction, and superficial tampering computationally expensive and forensically detectable through mathematical cryptographic signatures.
- 100% Offline / Local-First: No telemetry, no remote servers, no network dependencies.
- Zero PII in Payloads: Only opaque 128-bit cryptographic nonces are embedded in frequency coefficients. Personal data (NIK, names, tax numbers) is NEVER embedded into pixels.
- Battle-Tested Cryptography: Relies exclusively on standard, constant-time primitives (
ed25519-dalek,sha2,blake3,chacha20).
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'feat: Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT OR Apache-2.0 dual license. See LICENSE for more details.