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


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 40+ validators across South America

โœจ Key Features

๐Ÿ” Mathematical Validation

  • Brazil: CPF, CNPJ, RG, CNH, RENAVAM, Pix, License Plates
  • Argentina: CUIL/CUIT, DNI
  • Chile: RUT (full validation)
  • Colombia: Cรฉdula, NIT
  • Peru: DNI, RUC
  • Uruguay: CI, RUT
  • Venezuela: CI, RIF
  • Ecuador: Cรฉdula, RUC
  • Bolivia: CI, NIT
  • Paraguay: CI, RUC
  • International: Credit Cards (Luhn), IBAN, Email, Phone, Passport

๐Ÿฆ 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

๐Ÿš€ 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: โœ… 62/62 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

๐Ÿ‡ง๐Ÿ‡ท Brazil

  • โœ… CPF - Individual taxpayer ID (Mod 11 validation)
  • โœ… CNPJ - Company taxpayer ID (Weighted Mod 11)
  • โœ… RG - Identity card (format validation)
  • โœ… CNH - Driver's license (format validation)
  • โœ… RENAVAM - Vehicle registration (format validation)
  • โœ… Pix - Instant payment keys (UUID, Email, Phone)
  • โœ… Placa Mercosul - New license plates (ABC1D23)
  • โœ… Placa Antiga - Old license plates (ABC-1234)

๐Ÿ‡ฆ๐Ÿ‡ท Argentina

  • โœ… CUIL/CUIT - Tax identification number
  • โœ… DNI - National identity document

๐Ÿ‡จ๐Ÿ‡ฑ Chile

  • โœ… RUT - Tax identification number (full Mod 11 validation)

๐Ÿ‡จ๐Ÿ‡ด Colombia

  • โœ… Cรฉdula - National identity card
  • โœ… NIT - Tax identification number

๐Ÿ‡ต๐Ÿ‡ช Peru

  • โœ… DNI - National identity document
  • โœ… RUC - Tax identification number

๐Ÿ‡บ๐Ÿ‡พ Uruguay

  • โœ… CI - Identity card
  • โœ… RUT - Tax identification number

๐Ÿ‡ป๐Ÿ‡ช Venezuela

  • โœ… CI - Identity card
  • โœ… RIF - Tax identification number

๐Ÿ‡ช๐Ÿ‡จ Ecuador

  • โœ… Cรฉdula - Identity card (with province validation)
  • โœ… RUC - Tax identification number

๐Ÿ‡ง๐Ÿ‡ด Bolivia

  • โœ… CI - Identity card
  • โœ… NIT - Tax identification number

๐Ÿ‡ต๐Ÿ‡พ Paraguay

  • โœ… CI - Identity card
  • โœ… RUC - Tax identification number

๐Ÿ’ณ Finance (International)

  • โœ… Credit Cards - Visa, Mastercard, Amex, etc. (Luhn algorithm)
  • โœ… IBAN - International Bank Account Number (Mod 97 validation)

๐ŸŒ International

  • โœ… Email - Email addresses (RFC 5322 format)
  • โœ… Phone - International phone numbers
  • โœ… Passport - Passport numbers (alphanumeric format)

๐Ÿ“– 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

40+ validators covering all South American countries + 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. 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"}


</details>

<details>
<summary><b>๐Ÿ”น Django Integration</b></summary>

```python
# 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

๐Ÿ‡ง๐Ÿ‡ท Brazil

  • โœ… CPF - Individual taxpayer ID (Mod 11 validation)
  • โœ… CNPJ - Company taxpayer ID (Weighted Mod 11)
  • โœ… RG - Identity card (format validation)
  • โœ… CNH - Driver's license (format validation)
  • โœ… RENAVAM - Vehicle registration (format validation)
  • โœ… Pix - Instant payment keys (UUID, Email, Phone)
  • โœ… Placa Mercosul - New license plates (ABC1D23)
  • โœ… Placa Antiga - Old license plates (ABC-1234)

๐Ÿ‡ฆ๐Ÿ‡ท Argentina

  • โœ… CUIL/CUIT - Tax identification number
  • โœ… DNI - National identity document

๐Ÿ‡จ๐Ÿ‡ฑ Chile

  • โœ… RUT - Tax identification number (full Mod 11 validation)

๐Ÿ‡จ๐Ÿ‡ด Colombia

  • โœ… Cรฉdula - National identity card
  • โœ… NIT - Tax identification number

๐Ÿ‡ต๐Ÿ‡ช Peru

  • โœ… DNI - National identity document
  • โœ… RUC - Tax identification number

๐Ÿ‡บ๐Ÿ‡พ Uruguay

  • โœ… CI - Identity card
  • โœ… RUT - Tax identification number

๐Ÿ‡ป๐Ÿ‡ช Venezuela

  • โœ… CI - Identity card
  • โœ… RIF - Tax identification number

๐Ÿ‡ช๐Ÿ‡จ Ecuador

  • โœ… Cรฉdula - Identity card (with province validation)
  • โœ… RUC - Tax identification number

๐Ÿ‡ง๐Ÿ‡ด Bolivia

  • โœ… CI - Identity card
  • โœ… NIT - Tax identification number

๐Ÿ‡ต๐Ÿ‡พ Paraguay

  • โœ… CI - Identity card
  • โœ… RUC - Tax identification number

๐Ÿ’ณ Finance (International)

  • โœ… Credit Cards - Visa, Mastercard, Amex, etc. (Luhn algorithm)
  • โœ… IBAN - International Bank Account Number (Mod 97 validation)

๐ŸŒ International

  • โœ… Email - Email addresses (RFC 5322 format)
  • โœ… Phone - International phone numbers
  • โœ… Passport - Passport numbers (alphanumeric format)

๐Ÿ“– 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

40+ validators covering all South American countries + 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.0.tar.gz (71.2 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.0-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: opaque_logger-1.1.0.tar.gz
  • Upload date:
  • Size: 71.2 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.0.tar.gz
Algorithm Hash digest
SHA256 74495a37596132c70c2cba67c5e93dd77f856d677f1382f78ed081a8ccd89457
MD5 5254ccf3d330ae4a44ea25edd9b88e5b
BLAKE2b-256 c934a9b75fa6ec4fad2fd0620133b067e27c74fc5c4859bb759963e0e09445ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: opaque_logger-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1e484b699571593936926c6640c0cd4987655a6ab436876c527c29b4357b275
MD5 09cc5c1b86bd1339225c0bcaec1691ba
BLAKE2b-256 eff4c30238861c5857c76e19d1398f8f8bfdc26ede2f052ff3301c9b9557f346

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