THIS IS WORK IN PROGRESS!!
Hasher
is a customizable hashing tool implemented in Python. It allows users to hash various data types such as strings, integers, floats, lists, dictionaries, bytes, and even files with a standalone, configurable hashing algorithm. It offers additional security features such as configurable rounds, block sizes, and hash lengths, as well as optional salt
and pepper
for each hash.
- Supports hashing of multiple data types:
str
,int
,float
,list
,dict
,tuple
,bytes
, and files. - Customizable parameters:
rounds
: Number of rounds for the hashing process.block_size
: Size of the data blocks used for hashing.hash_length
: Length of the final hash output.salt
: Optional salt to add randomness to the hash.pepper
: An additional user-defined key that acts as a second salt.
- Provides both
base64
andhex
output formats. - Standalone script that does not depend on external libraries like
hashlib
orhmac
.
Simply download or clone this repository. No additional libraries are required.
from configurable_hasher import ConfigurableHasher
# Initialize the hasher with custom parameters
hasher = ConfigurableHasher(
rounds=100,
block_size=512,
hash_length=256,
salt="custom_salt",
pepper="extra_secret_pepper",
output_format="base64"
)
# Hash a string
data = "hello world"
hash_value = hasher.hash(data)
print(f"Hash of '{data}': {hash_value}")
# Hash an integer
integer_data = 12345
integer_hash = hasher.hash(integer_data)
print(f"Hash of {integer_data}: {integer_hash}")
# Hash a file
file_path = "example.txt"
file_hash = hasher.hash_file(file_path)
print(f"Hash of file '{file_path}': {file_hash}")
To ensure the integrity of a hashed item, use the validate
or validate_file
method to compare the computed hash with an existing hash.
# Validate a string hash
is_valid = hasher.validate(data, hash_value)
print(f"Is the hash valid? {is_valid}")
# Validate a file hash
is_file_valid = hasher.validate_file(file_path, file_hash)
print(f"Is the file hash valid? {is_file_valid}")
- Data Integrity Verification: Use this tool to verify if data has been altered by comparing the hash before and after.
- Password Storage: Store passwords as salted and hashed strings for enhanced security.
- File Change Detection: Monitor changes in files by hashing their content and comparing it with stored hash values.
The following parameters can be configured in the ConfigurableHasher
class:
rounds
(int): Number of rounds to use in the hashing algorithm. Minimum is64
.block_size
(int): Size of the data blocks for hashing in bits, must be between128
and2048
. Adjusted to be a multiple of64
.hash_length
(int): Length of the final hash output in bits, up to512
.salt
(Any): Optional salt for the hash. Acceptsstr
,int
,float
,list
,dict
,tuple
, andbytes
. It is converted to bytes and truncated/padded to16
bytes.pepper
(Any): Optional pepper for the hash. Accepts the same types assalt
, converted to bytes and truncated/padded to16
bytes.output_format
(str): Output format of the hash, either'hex'
or'base64'
.
The hash
method accepts a variety of data types:
str
: String data.int
: Integer data (signed and unsigned).float
: Floating-point numbers.list
: Lists containing any of the supported data types.dict
: Dictionaries with string keys and supported data types as values.tuple
: Tuples containing any of the supported data types.bytes
: Raw byte data.
- Integer Size: Integers are constrained by the
block_size
to prevent overflow errors. The maximum size is capped based on the block size in bits. - File Size: The maximum file size is limited by the available memory, as the file is processed in blocks equal to
block_size // 8
.
The ConfigurableHasher
offers a flexible and customizable hashing approach, but it's important to understand the security limitations:
- This hashing implementation is not cryptographically secure compared to standard algorithms like
SHA-256
orbcrypt
. - Suitable for data integrity checks or non-critical hashing needs, but not recommended for highly sensitive information such as password hashing in a production environment.
- Salting: The script allows for a fixed
salt
andpepper
, making it easier to validate hashes but less secure than dynamic salting for each hash. Always use unique salts when possible for added security.