Skip to main content

๐Ÿ›ก๏ธ Enterprise Data Masking Engine - Custom Callbacks, LGPD/GDPR Compliance, 77+ Validators, Zero False Positives

Project description

Python PyPI License Coverage

๐Ÿ‡บ๐Ÿ‡ธ English | ๐Ÿ‡ง๐Ÿ‡ท Portuguรชs | ๐Ÿ‡ช๐Ÿ‡ธ Espaรฑol


๐Ÿ›ก๏ธ OPAQUE

The only data masking library that uses MATH, not AI

๐ŸŽฏ Why OPAQUE?

Unlike AI-based solutions that guess, OPAQUE validates using mathematical algorithms:

Feature AI Solutions OPAQUE
Validation Neural networks (guessing) Mathematical algorithms (proof)
False Positives Common Zero
Performance Slow (GPU required) Ultra-fast (pure math)
Debuggability Black box Deterministic hashing
Reversibility No Yes (Vault Mode)
Coverage Limited 75+ validators globally

โœจ Key Features

๐Ÿ” Mathematical Validation

  • Global: 75+ validators across 5 continents.
  • Algorithms: Verhoeff, ISO 7064, Luhn, Mod 11.
  • Zero False Positives: Only mathematically valid data is masked.

๐Ÿฆ Vault Mode

  • AES-256 encryption
  • Reversible for debugging
  • CLI decryption tool
  • Master key protection
  • PBKDF2 key derivation

๐Ÿฏ Honeytokens

  • Intrusion detection
  • Bait data alerts
  • Real-time monitoring
  • Security integration
  • Automated alerts

โšก Circuit Breaker

  • Flood protection
  • Auto-recovery
  • Resource optimization
  • Server stability
  • Configurable thresholds

๐Ÿ›ก๏ธ Enterprise Customization & Compliance (New in v1.1.1)

OPAQUE v1.1.1 introduces powerful dependency injection to meet strict enterprise requirements:

๐Ÿ’‰ Dependency Injection

  • Custom Hash Functions: Inject your own hashing algorithms (e.g., HMAC-SHA512, Argon2).
  • Custom Vaults: Integrate with AWS Secrets Manager, HashiCorp Vault, or HSMs.
  • Custom Honeytoken Handlers: Check honeytokens against Redis, Databases, or external APIs.

โš–๏ธ LGPD & GDPR Compliance

We now provide explicit strategies for different compliance needs:

Strategy Class Use Case Reversible? Compliance
Anonymization IrreversibleAnonymizer Debugging, Errors โŒ No โœ… Not Personal Data
Pseudonymization DeterministicPseudonymizer Audit Trails โš ๏ธ Yes (with key) โš ๏ธ Personal Data

See our Compliance Guide for details.

๐Ÿš€ Quick Start

Installation

pip install opaque-logger

Basic Usage

import logging
from opaque import OpaqueLogger, Validators

# Configure
OpaqueLogger.setup_defaults(
    rules=[
        Validators.BR.CPF,
        Validators.BR.CNPJ,
        Validators.FINANCE.CREDIT_CARD
    ],
    obfuscation_method="HASH"
)

# Integrate
logging.setLoggerClass(OpaqueLogger)
logger = logging.getLogger("app")

# Log securely
logger.info("User CPF: 529.982.247-25")
# Output: User CPF: [HASH-3A4C]

logger.info("Invalid CPF: 111.222.333-44")
# Output: Invalid CPF: 111.222.333-44 (preserved for debugging)

๐Ÿ“Š Performance Benchmarks

Sanitization:     1,000+ messages/sec
CPF Validation:   65,000+ ops/sec
CNPJ Validation:  68,000+ ops/sec
Credit Card:      122,000+ ops/sec
Vault Encryption: 22,000+ ops/sec
Vault Decryption: 12,000+ ops/sec

๐Ÿงช Test Coverage

pytest -v

Results: โœ… 100+ tests passing (100% success rate)

  • โœ… All validators tested with valid and invalid data
  • โœ… Vault encryption/decryption
  • โœ… Honeytoken detection
  • โœ… Circuit breaker activation
  • โœ… Crash handler sanitization
  • โœ… Middleware integration
  • โœ… CLI tools

๐Ÿ“š Examples

๐Ÿ”น Vault Mode (Reversible Encryption)
import os
from opaque import OpaqueLogger, Validators

# Set master key
os.environ["OPAQUE_MASTER_KEY"] = "your-master-key"

OpaqueLogger.setup_defaults(
    rules=[Validators.BR.CPF],
    obfuscation_method="VAULT",
    vault_key="your-master-key"
)

logger = logging.getLogger("secure")
logger.info("Processing CPF 529.982.247-25")
# Output: Processing CPF [VAULT:gAAAAABl...]

# Decrypt later
python -m opaque.cli reveal "[VAULT:gAAAAABl...]" --key=your-master-key
# Output: ๐Ÿ”“ REVEALED DATA: 529.982.247-25
๐Ÿ”น Honeytokens (Intrusion Detection)
OpaqueLogger.setup_defaults(
    rules=[Validators.BR.CPF],
    honeytokens=["999.888.777-66"]  # Bait CPF
)

logger = logging.getLogger("security")
logger.info("Access with CPF 999.888.777-66")
# Stderr: ๐Ÿšจ ALERTA VERMELHO: HONEYTOKEN DETECTED: 999.888.777-66
# Output: Access with CPF [HONEYTOKEN TRIGGERED]
๐Ÿ”น Crash Handler (Traceback Sanitization)
from opaque import install_crash_handler, OpaqueLogger, Validators

# Setup
OpaqueLogger.setup_defaults(rules=[Validators.BR.CPF])
install_crash_handler()

# Now all crashes sanitize sensitive data
password = "secret123"
cpf = "529.982.247-25"
raise ValueError(f"Error: {cpf}")
# Traceback shows: ValueError: Error: [HASH-3A4C]
# Locals show: password = [REDACTED_SECRET_KEY]
๐Ÿ”น Multi-Country Support
from opaque import OpaqueLogger, Validators

# Configure for multiple countries
OpaqueLogger.setup_defaults(
    rules=[
        Validators.BR.CPF,      # Brazil
        Validators.AR.DNI,      # Argentina
        Validators.CL.RUT,      # Chile
        Validators.CO.CEDULA,   # Colombia
        Validators.PE.DNI,      # Peru
        Validators.FINANCE.CREDIT_CARD,  # International
    ]
)

logger = logging.getLogger("latam")
logger.info("BR CPF: 529.982.247-25")  # Sanitized
logger.info("CL RUT: 12.345.678-5")    # Sanitized
logger.info("Card: 4532-1488-0343-6467")  # Sanitized
๐Ÿ”น Compliance Scanning
# Scan your codebase for sensitive data
python -m opaque.cli scan ./src --output=report.html

# Output:
# ๐Ÿ” Scanning directory: ./src...
# โœ… Report generated: report.html
# ๐Ÿ›ก๏ธ Security Score: 98%
# 
# Found:
# - 15 CPF instances
# - 8 CNPJ instances
# - 3 Credit Card instances
# 
# Recommendations:
# - Use OpaqueLogger in production
# - Enable Vault mode for debugging
# - Add honeytokens for intrusion detection
๐Ÿ”น FastAPI Middleware
from fastapi import FastAPI
from opaque.middleware import OpaqueFastAPIMiddleware
from opaque import OpaqueLogger, Validators

app = FastAPI()

OpaqueLogger.setup_defaults(
    rules=[Validators.BR.CPF, Validators.BR.CNPJ]
)

# Middleware will sanitize all request/response data
app.add_middleware(OpaqueFastAPIMiddleware, logger=OpaqueLogger("api"))

@app.post("/payment")
async def process_payment(cpf: str, amount: float):
    # CPF will be automatically sanitized in logs
    return {"status": "success"}
๐Ÿ”น Django Integration
# settings.py
MIDDLEWARE = [
    'opaque.middleware.OpaqueDjangoMiddleware',
    # ... other middleware
]

# Configure in apps.py or __init__.py
from opaque import OpaqueLogger, Validators

OpaqueLogger.setup_defaults(
    rules=[Validators.BR.CPF, Validators.BR.CNPJ]
)

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   OPAQUE Engine                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  1. Context-Aware Regex Pattern Matching           โ”‚
โ”‚  2. Mathematical Validation (Mod 11, Luhn, etc.)   โ”‚
โ”‚  3. Honeytoken Detection                            โ”‚
โ”‚  4. Circuit Breaker Check                           โ”‚
โ”‚  5. Obfuscation (Hash/Vault/Mask)                  โ”‚
โ”‚  6. Structured Data Processing (JSON/Dict/List)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Processing Flow

Input Log Message
       โ†“
[Honeytoken Check] โ†’ Alert if detected
       โ†“
[Regex Pattern Matching] โ†’ Find potential sensitive data
       โ†“
[Mathematical Validation] โ†’ Verify using algorithms
       โ†“
[Circuit Breaker] โ†’ Prevent flood attacks
       โ†“
[Obfuscation] โ†’ Hash/Vault/Mask
       โ†“
Output Sanitized Message

๐ŸŒ Supported Validators (v1.1.2)

OPAQUE now supports 75+ validators across the globe, powered by advanced mathematical algorithms (Verhoeff, ISO 7064, Luhn, Mod 11).

๐ŸŒŽ North America

  • ๐Ÿ‡บ๐Ÿ‡ธ USA: SSN, EIN, ITIN
  • ๐Ÿ‡จ๐Ÿ‡ฆ Canada: SIN (Social Insurance Number)
  • ๐Ÿ‡ฒ๐Ÿ‡ฝ Mexico: CURP (Clave รšnica de Registro de Poblaciรณn)

๐Ÿ‡ช๐Ÿ‡บ Europe

  • ๐Ÿ‡ฉ๐Ÿ‡ช Germany: Steuer-ID (Tax ID)
  • ๐Ÿ‡ซ๐Ÿ‡ท France: NIR (INSEE Code)
  • ๐Ÿ‡ช๐Ÿ‡ธ Spain: DNI, NIE
  • ๐Ÿ‡ฎ๐Ÿ‡น Italy: Codice Fiscale
  • ๐Ÿ‡ฌ๐Ÿ‡ง UK: NINO (National Insurance Number)
  • ๐Ÿ‡ช๐Ÿ‡บ Eurozone: IBAN (International Bank Account Number)

๐ŸŒ Asia

  • ๐Ÿ‡ฎ๐Ÿ‡ณ India: Aadhaar (Verhoeff Algorithm)
  • ๐Ÿ‡จ๐Ÿ‡ณ China: Resident Identity Card (Mod 11-2)

โ˜๏ธ Cloud & Tech Tokens

  • AWS: Access Keys (AKIA/ASIA)
  • Google: OAuth Tokens, API Keys
  • GitHub: Personal Access Tokens (Classic & Fine-grained)
  • Slack: Bot/User Tokens
  • Stripe: Live/Test API Keys
  • Facebook: Access Tokens
  • Security: Private Keys (RSA/DSA/EC), JWT, PEM Certificates, High Entropy Secrets

๐Ÿ‡ง๐Ÿ‡ท South America (Legacy Stronghold)

  • Brazil: CPF, CNPJ, RG, CNH, RENAVAM, Pix, CNS, Voter ID, License Plates
  • Argentina: CUIL/CUIT, DNI
  • Chile: RUT
  • Colombia: Cรฉdula, NIT
  • Peru: DNI, RUC
  • Uruguay: CI, RUT
  • Venezuela: CI, RIF
  • Ecuador: Cรฉdula, RUC
  • Bolivia: CI, NIT
  • Paraguay: CI, RUC

๐ŸŒ International Standards

  • Finance: Credit Cards (All major brands), IBAN, SWIFT/BIC
  • Network: IPv4, IPv6, MAC Addresses
  • Crypto: Bitcoin (P2PKH, P2SH, Bech32), Ethereum Addresses
  • Personal: Email (RFC 5322), Phone Numbers (E.164), Passports

๐Ÿ“– Documentation

Document Description
๐Ÿ‡บ๐Ÿ‡ธ English Guide Complete documentation in English
๐Ÿ‡ง๐Ÿ‡ท Guia em Portuguรชs Documentaรงรฃo completa em Portuguรชs
๐Ÿ‡ช๐Ÿ‡ธ Guรญa en Espaรฑol Documentaciรณn completa en Espaรฑol
๐Ÿ“š API Reference Detailed API documentation
๐Ÿ”ง Installation Guide Step-by-step installation
๐Ÿ—๏ธ Project Structure Architecture overview
๐Ÿค Contributing Contribution guidelines
๐Ÿ“ Changelog Version history

๐Ÿค Contributing

We welcome contributions! See our Contributing Guide for details.

Development Setup

# Clone repository
git clone https://github.com/SamuelSilvass/OPAQUE.git
cd OPAQUE

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -e ".[dev]"

# Run tests
pytest -v

# Run benchmarks
python benchmarks/benchmark.py

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Links

๐Ÿ† Why Choose OPAQUE?

โœ… Zero False Positives

Every match is mathematically validated. No guessing, no AI hallucinations.

โœ… Production-Ready

Used in enterprise environments processing millions of logs daily.

โœ… Comprehensive Coverage

75+ validators covering 5 continents + international standards.

โœ… Reversible Encryption

Debug production issues without exposing sensitive data.

โœ… Security First

Honeytokens, circuit breakers, and crash handlers protect your data.

โœ… Framework Agnostic

Works with FastAPI, Django, Flask, or any Python application.

โœ… Performance Optimized

Process thousands of messages per second without slowing down your app.


Built with precision by Samuel Silva

Protecting data with mathematics, not magic โœจ

GitHub Stars GitHub Forks

Made with โค๏ธ for the developer community


๐Ÿ“ง Contact

For questions, suggestions, or support, please contact:

Email: ssanches011@gmail.com

Or open an issue on GitHub Issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opaque_logger-1.1.2.tar.gz (70.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opaque_logger-1.1.2-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file opaque_logger-1.1.2.tar.gz.

File metadata

  • Download URL: opaque_logger-1.1.2.tar.gz
  • Upload date:
  • Size: 70.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for opaque_logger-1.1.2.tar.gz
Algorithm Hash digest
SHA256 8462d37cae85b07b2abcba8623d63d3a2b3efd115e343ade238fe7aa557b5ab8
MD5 351650462a366d1e261283acfaa71bbb
BLAKE2b-256 034249eb5aa4d2a193d0d4b84a11b60852e16b648eb41660189367bf05e7860c

See more details on using hashes here.

File details

Details for the file opaque_logger-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: opaque_logger-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for opaque_logger-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f3ad651f521a2ac3a564a4e6cd4e3b216ad7a40f9b8b1772920510fdfc3ce80e
MD5 8cee7868cc26a7bb3562bdf41adfae6c
BLAKE2b-256 f01e1686cfdcc135c8a71d79d050eae359d98567e10cbba3b09e2c5d0b651e9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page