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.2.tar.gz (5.0 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.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: encryptools-1.2.2.tar.gz
  • Upload date:
  • Size: 5.0 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.2.tar.gz
Algorithm Hash digest
SHA256 997f570babf99607b151b87037776455ccee3723246c12776a4d16e527fd724c
MD5 91a7e8b57b76edd09f558726f71c1375
BLAKE2b-256 e2c0fd7470967d8fc1056762086e6b1b49dd770e7be3b915ae4b97408da978bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: encryptools-1.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 28ddd4ece6c49755119fbc565f74b019de088a46f7440a9e4eb4a7172785f16f
MD5 c7efb2d66ff762f98cfb0f41ff4f126f
BLAKE2b-256 1b4c8a6058b945bdd749ad76f6a7a065ed2f4f4ab19331967d28035b0d194243

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