Stateless-overwrite hybrid cryptosystem for Python
Project description
Hycrypt
Stateless-overwrite hybrid cryptosystem for Python
Hycrypt is a stateless-overwrite hybrid cryptosystem designed for secure data encryption and password-free updates. This makes it ideal for secure communication and storage systems where only the recipient can decrypt the data — yet the data can be updated without the password.
The caveat is that this cryptosystem does not guarantee authenticity of the message. Anyone with the public key can overwrite the message. However, without the private key (or password), they cannot read the encrypted message.
Features
- 🔒 Hybrid encryption using RSA + AES-CBC + HMAC
- 🔁 Stateless overwrite using only the public key, removing the need to retain user secrets
- 🔑 Password-based protection using PBKDF2
- 📦 Simple, yet flexible API for file-based and in-memory encryption
Quick Start
Using FileCipher to manage file encryption,
from hycrypt.file_cryptosystem import FileCipher
file = "home/data.txt"
plaintext = b"secret"
password = b"correcthorsebatterystaple"
cipher = FileCipher(file)
cipher.create(password)
cipher.write(plaintext)
decrypted_text = cipher.read(password)
For more flexible use,
import hycrypt
plaintext = b"secret"
ciphertext, public_key = hycrypt.encrypt_with_password(plaintext, password=b"password1")
decrypted_message = hycrypt.decrypt_with_password(ciphertext, password=b"password1")
assert decrypted_message == plaintext
new_plaintext = b"my new secret"
new_ciphertext = hycrypt.encrypt_with_public_key(previous_data=ciphertext, plaintext=new_plaintext, public_key=public_key)
new_decrypted_message = hycrypt.decrypt_with_password(new_ciphertext, password=b"password1")
assert new_decrypted_message == new_plaintext
See examples and use cases in examples/.
To install hycrypt using pip:
pip install hycrypt
How It Works
Encryption
- A symmetric key is randomly generated to encrypt to plaintext into ciphertext. The encryption uses Fernet implementation by cryptography.
- An RSA key pair (private and public key) is generated.
- The public key is used to encrypt the symmetric key. The public key can be shared safely.
- The user selects a password.
- The password is combined with a random salt to produce a password-derived symmetric key using
PBKDF2(Password-Based Key Derivation Function 2). - The password-derived key is used to encrypt the private key.
- The ciphertext is stored along with the encrypted symmetric key, the salt, and the encrypted private key.
Decryption
- The user inputs the password.
- The password is combined with the stored salt using
PBKDF2to recreate the same password-derived symmetric key. - The password-derived key decrypts the private key in the file.
- The recovered private key decrypts the symmetric key that was used to encrypt the file data.
- The symmetric key decrypts the ciphertext into plaintext.
Overwriting Data Without Password
- A new symmetric key is generated randomly.
- The symmetric key encrypts the new plaintext into ciphertext.
- The original public key is used to encrypt the new symmetric key.
- The file is updated with the new encrypted symmetric key and the new ciphertext.
Despite the writer not knowing the password, the data can be overwritten using public key. The encrypted private key remains a secret. Because the encrypted private key corresponds to the public key, the recipient who knows the password can still decrypt the data.
Disclaimer
Hycrypt is intended for educational and experimental uses. While it employs reasonably secure cryptographic practices, it has not undergone formal security audits. Hence, it is not recommended for production environment without thorough review and modification. Consider opening an issue or submitting a pull request for potential issues and improvement.
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 hycrypt-1.1.tar.gz.
File metadata
- Download URL: hycrypt-1.1.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
becfd0bc05e904ce67d2c0196a7fa3eadfe33089d409c8cba44330113ed25ef3
|
|
| MD5 |
65d773449a322b2f748626457c81d42d
|
|
| BLAKE2b-256 |
d96262367bd447751ab885fcb8939513f98b419410849a992c567e363ddd7f27
|
Provenance
The following attestation bundles were made for hycrypt-1.1.tar.gz:
Publisher:
python-publish.yml on p-sira/hycrypt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hycrypt-1.1.tar.gz -
Subject digest:
becfd0bc05e904ce67d2c0196a7fa3eadfe33089d409c8cba44330113ed25ef3 - Sigstore transparency entry: 226827698
- Sigstore integration time:
-
Permalink:
p-sira/hycrypt@71ebc4e98d5cdb9960f808377d4ed35f9fa0845a -
Branch / Tag:
refs/tags/1.1 - Owner: https://github.com/p-sira
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@71ebc4e98d5cdb9960f808377d4ed35f9fa0845a -
Trigger Event:
release
-
Statement type:
File details
Details for the file hycrypt-1.1-py3-none-any.whl.
File metadata
- Download URL: hycrypt-1.1-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0d9679444a87613e8661a718bc9804c21baecaaae21be9400062009c66ca5da
|
|
| MD5 |
c9cf6d4083dd9e7efe917191d78f8151
|
|
| BLAKE2b-256 |
390a5c30de656d7a3666c596bcbaa6256c8eb499328d30af9ee5ee5edd94dcdb
|
Provenance
The following attestation bundles were made for hycrypt-1.1-py3-none-any.whl:
Publisher:
python-publish.yml on p-sira/hycrypt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hycrypt-1.1-py3-none-any.whl -
Subject digest:
d0d9679444a87613e8661a718bc9804c21baecaaae21be9400062009c66ca5da - Sigstore transparency entry: 226827699
- Sigstore integration time:
-
Permalink:
p-sira/hycrypt@71ebc4e98d5cdb9960f808377d4ed35f9fa0845a -
Branch / Tag:
refs/tags/1.1 - Owner: https://github.com/p-sira
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@71ebc4e98d5cdb9960f808377d4ed35f9fa0845a -
Trigger Event:
release
-
Statement type: