Multilayer SHA-512 hashing utility for PII columns in CSV/TXT files
Project description
d2-hasher
Multilayer SHA-512 hashing utility for PII columns in CSV/TXT files.
Installation
pip install d2-hasher
Quick Start
Python API
from d2_hasher import hash_columns
# Hash columns in a CSV file
hash_columns(
input_file="data.csv",
columns=["national_id", "name"],
secret_salts=["your_secret_salt_1", "your_secret_salt_2"],
)
# Output written to data_hashed.csv
# Hash a DataFrame in-memory
import pandas as pd
df = pd.read_csv("data.csv")
result = hash_columns(
df=df,
columns=["national_id", "name"],
secret_salts=["your_secret_salt_1", "your_secret_salt_2"],
)
Command Line
d2-hasher \
--input-file data.csv \
--columns national_id name \
--secret-salts "your_secret_salt_1" "your_secret_salt_2" \
--output data_hashed.csv \
--chunksize 50000
hash_columns() Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
columns |
list[str] |
Yes | — | Column names to hash |
secret_salts |
list[str] |
Yes | — | Secret salts applied in order |
input_file |
str |
No* | — | Path to CSV/TXT file |
df |
DataFrame |
No* | — | In-memory DataFrame |
output |
str |
No | <stem>_hashed.csv |
Output file path |
chunksize |
int |
No | 10000 |
Rows per chunk |
delimiter |
str |
No | auto-detect | Column delimiter |
* At least one of input_file or df must be provided.
Algorithm
For each value:
- Normalize: CID must be exactly 13 consecutive Arabic digits with no hyphens (
-), spaces, or any special characters - For each secret salt:
SHA-512(value + salt)→ 128-char hex string - Use the output of one round as input to the next
Null/NaN values are returned as None without hashing.
CLI Reference
d2-hasher --input-file FILE --columns COL [COL ...] --secret-salts SALT [SALT ...]
[--output FILE] [--chunksize N] [--delimiter CHAR]
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
d2_hasher-1.1.1.tar.gz
(8.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file d2_hasher-1.1.1.tar.gz.
File metadata
- Download URL: d2_hasher-1.1.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07e8eb9490fb75694ba5ed67691586e265926e134fa910ac8916f5027b14576a
|
|
| MD5 |
605266e1101eb4e0370c19f868cf175f
|
|
| BLAKE2b-256 |
340385a8936ea40ab31ef9f9bd5de2718b5725acc7121716cff92072556bbd54
|
File details
Details for the file d2_hasher-1.1.1-py3-none-any.whl.
File metadata
- Download URL: d2_hasher-1.1.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0e91feefe5acde1733e7bb9da9b769cc1c1167662e6b505654312758cfb0840
|
|
| MD5 |
5918a07ff63ca0a9161c0c5b80d9f019
|
|
| BLAKE2b-256 |
e296a64138ddf5709f4707cc80eab39c80fdba5140a68a4181036a33e6966466
|