Skip to content

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ DocSeal

Privacy-First Document Watermarking, Tamper Detection & Cryptographic Provenance Toolkit in Pure Rust

CI Release License: MIT OR Apache-2.0 Rust: 1.80+ Local-First GitHub stars

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


🌟 Why DocSeal?

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.

πŸš€ Key Features

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 $GF(2^8)$ ECC 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

🎯 Common Use Cases

  1. 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").
  2. Tax & Financial Compliance:
    • Watermarking NPWP (Tax ID Cards), SPT reports, electronic invoices, and bank statements.
  3. Enterprise & Legal Contracts:
    • Signing and watermarking confidential NDAs, employment agreements, university diplomas, and audit certificates.
  4. Anti-Fraud & Fintech Verification:
    • Automated server-side document provenance verification using high-throughput Rust subroutines (< 11ms latency).

πŸ—οΈ System Architecture

                            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

πŸ“¦ Workspace Crate Ecosystem

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

⚑ Quick Start

Installation

Option 1: Build from Source

git clone https://github.com/egagofur/DocSeal.git
cd DocSeal
cargo build --release -p docseal

# Binary available at target/release/docseal

Option 2: Precompiled Binaries

Download the latest binaries for Linux, macOS (Apple Silicon / Intel), and Windows from the Releases page.


πŸ’» CLI Usage Guide

1. Generate an Ed25519 Issuer Keypair

docseal keygen --output issuer_key.bin

Output:

πŸ”‘ Generated Ed25519 Issuer Keypair
  Public DID Key:  did:key:z6MkwSbVf5Lh...
  Raw Private Key: 8a3b4...
  Key written to:  issuer_key.bin

2. Protect an Image (KTP / Passport / ID)

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.json

3. Protect a Vector PDF (No Rasterization)

docseal protect statement.pdf \
  --text "FOR VISA APPLICATION ONLY" \
  --sign-key issuer_key.bin \
  --output statement_protected.pdf

4. Verify Document Authenticity & Integrity

docseal 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
──────────────────────────────────────────────────

πŸ¦€ Rust Developer API

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" }

Protecting an Image in Rust

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(())
}

πŸ“Š Empirical Benchmarks

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

High Throughput Performance

  • 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.


πŸ”’ Security Principles & Privacy Safeguards

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.

  1. 100% Offline / Local-First: No telemetry, no remote servers, no network dependencies.
  2. 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.
  3. Battle-Tested Cryptography: Relies exclusively on standard, constant-time primitives (ed25519-dalek, sha2, blake3, chacha20).

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat: Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“œ License

Distributed under the MIT OR Apache-2.0 dual license. See LICENSE for more details.


Built with ❀️ in pure Rust for privacy and digital document integrity.

About

πŸ›‘οΈ Privacy-first, local-first document watermarking and cryptographic provenance toolkit in pure Rust. Protect KTP, passports, NPWP, and PDFs from identity fraud and tampering.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages