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

Uploaded Python 3

File details

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

File metadata

  • Download URL: encryptools-1.2.0.tar.gz
  • Upload date:
  • Size: 5.3 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.0.tar.gz
Algorithm Hash digest
SHA256 01a56cdce1e50425c8a3da08366c369e6ec4118c4b05aa6d910f1117c057119c
MD5 0a06903df53e9b448a2c41b3ed3363d7
BLAKE2b-256 b63d8e5c39c0a6c1930e8eba48e976924dc6b89c722c6313219ffc28dac37ca4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: encryptools-1.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ff32ab9846ede09be17a8a9e326a12622a8dc80dc6bcd5dfb7566d9dafdc19b
MD5 959f660f26014f75f589a5703f05a74c
BLAKE2b-256 0528cc0b04c021bc19b88ec6a85395a30e89856bea4942bc1366c70431b7df72

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