Skip to main content

Encrypt and Decrypt file python

Project description

Encryptools

PyPI version License: MIT Python versions

Encryptools is a Python package that provides tools for encrypting and decrypting files using a combination of AES and RSA encryption. This package is designed to simplify the process of securing sensitive data.

Features

  • Generate RSA key pairs
  • Encrypt files using AES symmetric encryption
  • Encrypt AES keys with RSA for secure key transmission
  • Create decryption scripts to easily decrypt the files

Installation

Encryptools can be installed from PyPI using pip:

pip install encryptools

## Usage

### Generating RSA Keys

You can generate RSA key pairs using the `RSAKeyManager` class:

```python
from encryptools import RSAKeyManager

rsa_manager = RSAKeyManager()
private_key, public_key = rsa_manager.generate_rsa_keys()

# Save keys to files
rsa_manager.save_rsa_key(private_key, public_key, "private_key.pem", "public_key.pem")

Encrypting Data

Encrypt data using the HybridEncryptor class, which combines AES and RSA encryption:

from encryptools import HybridEncryptor

hybrid_encryptor = HybridEncryptor()
data = b"Hello, World!"

# Load public key
with open("public_key.pem", "rb") as f:
    public_key = f.read()

encrypted_symmetric_key, iv, ct_bytes = hybrid_encryptor.hybrid_encrypt(data, public_key)

print("Encrypted symmetric key:", encrypted_symmetric_key)
print("IV:", iv)
print("Ciphertext:", ct_bytes)

Decrypting Data

Decrypt data using the HybridEncryptor class:

# Load private key
with open("private_key.pem", "rb") as f:
    private_key = f.read()

decrypted_data = hybrid_encryptor.hybrid_decrypt(encrypted_symmetric_key, iv, ct_bytes, private_key)

print("Decrypted data:", decrypted_data)

Creating Decryption Scripts

Create a decryption script that can be used to decrypt the file later:

from encryptools import DecryptFileCreator

decrypt_file_creator = DecryptFileCreator(symmetric_key)
decrypt_file_creator.write_decrypt_function_to_file("decrypt_script.py", "encrypted_file.bin", "decrypted_file.txt")

Running Tests

To run the tests, use the following command:

python -m unittest discover -s tests

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

  1. Fork the repository
  2. Create a new branch: git checkout -b my-feature-branch
  3. Make your changes and commit them: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-feature-branch
  5. Submit a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

If you have any questions, feel free to open an issue or contact me at ardionefarisi1322@gmail.com.


Happy encrypting!


### Explanation:

1. **Title and Badges**: The title of the package and badges for version, license, and supported Python versions.
2. **Features**: A brief list of what the package can do.
3. **Installation**: Instructions on how to install the package using pip.
4. **Usage**: Detailed code examples on how to generate RSA keys, encrypt data, decrypt data, and create decryption scripts.
5. **Running Tests**: Instructions on how to run tests for the package.
6. **Contributing**: Guidelines for contributing to the project.
7. **License**: Information about the project's license.
8. **Contact**: Contact information for further questions or support.

Feel free to customize the contact information and any other section according to your specific needs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

encryptools-1.2.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

encryptools-1.2.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file encryptools-1.2.1.tar.gz.

File metadata

  • Download URL: encryptools-1.2.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for encryptools-1.2.1.tar.gz
Algorithm Hash digest
SHA256 8cb056ff584625e9638b635d402b25f68c13f49185f8eeb0f3cc160991fe398d
MD5 d37587b7fc26cc6dd0004abd620d8929
BLAKE2b-256 506538acc7b2f1d37c6d089d1f2d593b56392ae05becc2baf49e409f046c89d3

See more details on using hashes here.

File details

Details for the file encryptools-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: encryptools-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for encryptools-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fba6c2bce603c86bfde766c214a65a9fc1bc75b9d1bab295771e9c9b77656ac3
MD5 aa2cefb446c75d0a23993207267bd6db
BLAKE2b-256 4170acb026feab5bf61d2cf8e298e27d94bc781e9687218888b8e637d8e55869

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page