Python utility to cryptographically lock secrets for a preset amount of time.
Project description
TimeRelease
Introduction
A simple Python utility to lock (or encrypt) secrets, such that they require a preset amount of compute to unlock (or decrypt) them later.
Since each cryptographic step requires the last, it (by design) cannot be parallelized.
This could potentially be useful if you want to wait, for example, an hour, before being able to access a password; as a form of stolen device protection.
WARNING!
Always keep your "encrypted" file secret, treating it as if it were a password. It is effectively unencrypted as it can be used to decrypt the secret (if such an attacker has sufficient time to complete the puzzle) without any other knowledge of the secret or the individual who encrypted it.
Table of Contents
Usage
Setup
Install the package and its dependencies in a venv:
python3 -m venv ./venv
source ./venv/bin/activate
pip install TimeRelease
Encryption
To encrypt a file somefile.txt -> somefile.txt.timerelease:
# Specify # of seconds it should take to unlock on your machine
timerelease --encrypt somefile.txt somefile.txt.timerelease --time 3600
# Or, specify raw # of iterations needed to unlock the file
timerelease --encrypt somefile.txt somefile.txt.timerelease --iters 1073741824
You can use this to determine how long (on your hardware) the decryption process will take. Encryption should be nearly instant for most settings, even for comically large numbers of iterations.
Decryption
To decrypt a file somefile.txt.timerelease -> somefile.txt:
timerelease --decrypt somefile.txt.timerelease somefile.txt
It will take however long the person who encrypted the file dictates. The only way to speed it up is to find a CPU with really, really fast single-core performance.
Module API
Like any module, TimeRelease can be installed via pip (pip install TimeRelease) and imported (import TimeRelease). The API for the TimeRelease module is as follows:
TimeRelease.decrypt_secret(enc_package, logging=True)
- Given a dictionary which was generated by encrypt_secret(), decrypt_secret() decrypts it and returns the secret as a byte string.
- If
logging(defaults to True) is set to True, a progress bar is printed, along with extra debug information.
TimeRelease.encrypt_secret(secret, iterations, logging=True)
- Given a byte string
secret, encrypt_secret() appliesiterationsiterations to it, "encrypting" it. - If
logging(defaults to True) is set to True, extra debug information is printed.
TimeRelease.run_single_benchmark(iterations, logging=True)
- Determines how long it takes for the CPU to run a fixed number of
iterations. - Amount of time elapsed is returned in seconds as a float.
- If
logging(defaults to True) is set to True, extra debug information is printed.
TimeRelease.run_benchmark(benches, logging=True)
- Determines how many iterations a single core of the user's CPU is capable of processing, on average, per second (as an integer).
benches(defaults to 10) describes the number of times the benchmark will be run.- Higher values of
benches= greater certainty in running time, but more time is spent benchmarking. - If
logging(defaults to True) is set to True, extra debug information is printed.
Development Usage
To install development versions of this package, clone this repo and cd into it, then run:
python3 -m venv ./venv
source ./venv/bin/activate
pip install -e .[dev]
pre-commit install
To test the codebase, simply run pytest. To apply proper formatting to the codebase, run ruff format .. To ensure that the code has no other issues with PEP8 compliance, run ruff check. And to ensure that there are no type errors, please run ty check TimeRelease. Please do all of these things before you commit, and not after!
To build a distribution package, first update the version number in pyproject.toml, and make a tag for that release version at the current commit. Then:
python3 -m build
To upload this build to PyPI, run:
python3 -m twine upload dist/* --skip-existing
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
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 timerelease-2.0.0.tar.gz.
File metadata
- Download URL: timerelease-2.0.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
188df7d1ae328b3afee6a3ae6da42d867f388c1ba83ad227aa8b0654178b7f2d
|
|
| MD5 |
542a6cd6e77b1441c01f666d3a2bd998
|
|
| BLAKE2b-256 |
00569770f9b0f8ddf19312ce65fa6d82b3cded3c2fedbfcc6711aae03aaa8634
|
File details
Details for the file timerelease-2.0.0-py3-none-any.whl.
File metadata
- Download URL: timerelease-2.0.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
596c8b6ff5e76366242443a1ac472d94ca8aca92d34d103a9f2d89932e8ca1f6
|
|
| MD5 |
be10769ac2d689de6ecd5f142c1647b9
|
|
| BLAKE2b-256 |
48addb869329b36171ce1ce2d39cd6a68285696bfb1ad9daa3ffe94a7487fbb8
|