Una suite de herramientas open-source diseñada para gestionar el ciclo de vida de documentos sensibles: anonimización automática de identificadores españoles (DNI/NIE), firma criptográfica y verificación de integridad.
Ideal para la publicación transparente de documentos oficiales o personales, asegurando que no contienen datos privados (NIFs) y garantizando que no han sido manipulados tras su publicación.
El sistema funciona en tres etapas:
- Limpieza (
redact_nif.py): Detecta y censura permanentemente DNI/NIEs en PDFs. - Sellado (
sign_docs.sh): Firma digitalmente los documentos limpios y genera hashes de integridad. - Verificación (
check_docs.sh): Cualquiera puede comprobar que los documentos son auténticos y no han sido alterados.
Las herramientas están diseñadas para Linux, macOS y WSL (Windows Subsystem for Linux).
- Python 3.6+
- GnuPG (
gpg): Para las firmas digitales. - OpenSSL (Opcional): Para el sellado de tiempo (TSA).
# 1. Crear entorno virtual (Recomendado)
python3 -m venv venv
source venv/bin/activate
# 2. Instalar librería de procesamiento PDF
pip install PyMuPDF
# 3. Asegurar permisos de ejecución
chmod +x redact_nif.py sign_docs.sh check_docs.shEscanea recursivamente un directorio en busca de PDFs, detecta NIF/NIEs válidos (calculando la letra de control) y aplica una censura negra permanente (no reversible).
./redact_nif.py -i /ruta/a/documentos_origen- Genera una carpeta
redacted_outputcon la misma estructura que el origen. - Crea un log
redaction_log.jsonlcon todos los hallazgos.
Toma los documentos limpios y genera un paquete de distribución verificable.
./sign_docs.sh -i redacted_output -o documentos_finales -u tu_email@ejemplo.com-i: Carpeta con los PDFs limpios.-o: Carpeta de destino.-u: Tu ID o Email de tu clave GPG privada.-t(Opcional): URL de una Autoridad de Sellado de Tiempo (ej. FNMT) para certificar cuándo se firmó.
Resultado en documentos_finales/:
pdf_signed/: Copia de los PDFs.pgp_asc/: Firmas digitales individuales (.asc) para cada PDF.SHA512SUMS: Lista maestra de hashes sha512.SHA512SUMS.asc: Firma de la lista maestra.publickey.asc: Tu clave pública para que otros puedan verificarte.
Este script se entrega junto con los documentos. Permite a terceros validar toda la cadena de confianza con un solo comando.
./check_docs.sh -i documentos_finalesEl script verificará:
- ✅ Que la clave pública incluida es válida.
- ✅ Que el manifiesto
SHA512SUMSestá firmado por esa clave. - ✅ Que todos los archivos coinciden con su hash SHA512 (integridad bit a bit).
- ✅ Que cada PDF individual tiene una firma PGP válida.
- ✅ (Opcional) La validez del sello de tiempo TSA.
Este conjunto de herramientas está diseñado para proporcionar garantías técnicas que respaldan la validez legal de los documentos, especialmente útil frente a alteraciones malintencionadas por terceros.
- Integridad: El hash SHA-512 garantiza matemáticamente que el documento no ha sido modificado en un solo bit desde su sellado.
- No Repudio: La firma digital PGP vincula inequívocamente al firmante con el documento. El autor no puede negar haberlo firmado si se verifica con su clave pública.
- Prueba de Existencia: Si se utiliza el sellado de tiempo (TSA), se certifica que el documento existía en un momento exacto, impidiendo la retrodatación fraudulenta.
Nota: Estas herramientas proporcionan la evidencia técnica necesaria para procesos periciales, aunque la validez final depende del marco legal específico aplicable.
- Nunca publiques/compartas la clave privada bajo ningún contexto. ¡Guárdala como oro en paño!
- Todos los documentos procesados y archivos generados por los scripts deberían ser publicados conjuntamente. Sin todos ellos, la cadena de confianza se rompe.
- Nunca modifiques en absolutamente nada los archivos generados. De cambiar un solo bit, las distintas verificaciones fallarán rotundamente. Si necesitas modificar algo, vuelve a repetir el proceso completo y reemplaza los nuevos archivos generados por los antiguos.
¡Las contribuciones son bienvenidas! Mantén el código modular, legible y testeado. Los pull requests deben incluir una descripción clara y un ejemplo de funcionamiento.
MIT © 2026 sandokan.cat
Úsalo. Modifícalo. Compártelo. Se agradece la atribución.
Todas las herramientas y utilidades de este repositorio se proporcionan "tal cual", sin garantías. Úsalas bajo tu propia responsabilidad. Pensado para uso personal, educativo y profesional.
🇬🇧 English
An open-source suite designed to manage the lifecycle of sensitive documents: automatic anonymisation of Spanish identifiers (DNI/NIE), cryptographic signing, and integrity verification.
Ideal for transparent publication of official or personal documents, ensuring they contain no private data (NIFs) and guaranteeing they haven't been tampered with after publication.
The system works in three stages:
- Clean (
redact_nif.py): Detects and permanently redacts DNI/NIEs in PDFs. - Seal (
sign_docs.sh): Digitally signs cleaned documents and generates integrity hashes. - Verify (
check_docs.sh): Allows anyone to verify documents are authentic and unaltered.
Tools are designed for Linux, macOS, and WSL (Windows Subsystem for Linux).
- Python 3.6+
- GnuPG (
gpg): For digital signatures. - OpenSSL (Optional): For Timestamping (TSA).
# 1. Create virtual environment (Recommended)
python3 -m venv venv
source venv/bin/activate
# 2. Install PDF processing library
pip install PyMuPDF
# 3. Ensure execution permissions
chmod +x redact_nif.py sign_docs.sh check_docs.shRecursively scans a directory for PDFs, detects valid NIF/NIEs (calculating the check digit), and applies permanent black censorship (non-reversible).
./redact_nif.py -i /path/to/source_docs- Generates a
redacted_outputfolder with the same structure as source. - Creates a
redaction_log.jsonllog with all findings.
Takes cleaned documents and generates a verifiable distribution package.
./sign_docs.sh -i redacted_output -o final_docs -u your_email@example.com-i: Folder containing cleaned PDFs.-o: Destination folder.-u: Your private GPG Key ID or Email.-t(Optional): URL of a Timestamping Authority (e.g. FNMT) to certify when it was signed.
Result in final_docs/:
pdf_signed/: Copy of the PDFs.pgp_asc/: Individual digital signatures (.asc) for each PDF.SHA512SUMS: Master list of sha512 hashes.SHA512SUMS.asc: Signature of the master list.publickey.asc: Your public key for others to verify you.
This script is delivered alongside the documents. Allows third parties to validate the entire chain of trust with a single command.
./check_docs.sh -i final_docsThe script will verify:
- ✅ That the included public key is valid.
- ✅ That the
SHA512SUMSmanifest is signed by that key. - ✅ That all files match their SHA512 hash (bit-for-bit integrity).
- ✅ That each individual PDF has a valid PGP signature.
- ✅ (Optional) The validity of the TSA timestamp.
This toolset is designed to provide technical guarantees that support the legal validity of documents, particularly useful against malicious alterations by third parties.
- Integrity: The SHA-512 hash mathematically guarantees that the document has not been modified by a single bit since it was sealed.
- Non-repudiation: The PGP digital signature unequivocally links the signer to the document. The author cannot deny having signed it if verified with their public key.
- Proof of Existence: If timestamping (TSA) is used, it certifies that the document existed at an exact moment, preventing fraudulent backdating.
Note: These tools provide the necessary technical evidence for forensic processes, although final validity depends on the specific applicable legal framework.
- Never publish/share your private key under any context. Guard it with your life!
- All processed documents and generated files should be published together. Without all of them, the chain of trust is broken.
- Never modify the generated files in any way. Changing a single bit will cause validations to fail. If you need to modify something, repeat the entire process and replace the new generated files with the old ones.
Contributions are welcome! Keep code modular, readable, and tested. Pull requests should include a clear description and working example.
MIT © 2026 sandokan.cat
Use it. Modify it. Share it. Attribution is appreciated.
All tools and utilities in this repo are provided "as is", without warranties. Use at your own risk. Intended for personal, educational, and professional use.