https://github.com/smoren/encryptiontools-pypi
Tools for encryption and decryption, signing and verification. Use symmetric and asymmetric (RSA-based) encryption.
https://github.com/smoren/encryptiontools-pypi
cryptography decryption encryption pypi-package rsa rsa-cryptography signing verification
Last synced: 6 months ago
JSON representation
Tools for encryption and decryption, signing and verification. Use symmetric and asymmetric (RSA-based) encryption.
- Host: GitHub
- URL: https://github.com/smoren/encryptiontools-pypi
- Owner: Smoren
- License: mit
- Created: 2024-02-29T21:16:42.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-17T14:49:32.000Z (over 1 year ago)
- Last Synced: 2025-03-28T13:21:16.440Z (6 months ago)
- Topics: cryptography, decryption, encryption, pypi-package, rsa, rsa-cryptography, signing, verification
- Language: Python
- Homepage:
- Size: 36.1 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Encryption Tools for Python 3
[](https://pypi.org/project/encryptiontools/)
[](https://github.com/Smoren/encryptiontools-pypi/releases)
[](https://coveralls.io/github/Smoren/encryptiontools-pypi?branch=master)
[](https://github.com/Smoren/encryptiontools-pypi/actions)
[](https://github.com/Smoren/encryptiontools-pypi/blob/master/LICENSE)Tools for encryption and decryption, signing and verification. Use symmetric and asymmetric (RSA-based) encryption.
## Installation
```
pip install encryptiontools
```## Usage
### Asymmetric encryption and decryption
```python
from encryptiontools.encryption import AsymmetricEncrypter, AsymmetricDecrypter
from encryptiontools.utils import generate_key_pairpublic_key, private_key = generate_key_pair(512)
data = {'message': 'hello asymmetric encryption'}
encrypter = AsymmetricEncrypter.create(public_key.save_pkcs1()) # or AsymmetricEncrypter(public_key)
decrypter = AsymmetricDecrypter.create(private_key.save_pkcs1()) # or AsymmetricDecrypter(private_key)encrypted = encrypter.encrypt(data)
decrypted = decrypter.decrypt(encrypted)assert decrypted['message'] == 'hello asymmetric encryption'
```### Symmetric encryption and decryption
```python
from encryptiontools.encryption import SymmetricEncrypterkey = b'0123456789abcdef'
data = {'message': 'hello symmetric encryption'}
encrypter = SymmetricEncrypter.create(key) # or SymmetricEncrypter(key)
encrypted = encrypter.encrypt(data)
decrypted = encrypter.decrypt(encrypted)assert decrypted['message'] == 'hello symmetric encryption'
```### Combined encryption and decryption
Asymmetric key pair is used to encrypt/decrypt internal (symmetric) key, internal key is used to decrypt data.
```python
from encryptiontools.encryption import CombinedEncrypter, CombinedDecrypter
from encryptiontools.utils import generate_key_pairpublic_key, private_key = generate_key_pair(512)
data = {'message': 'hello combined encryption'}
encrypter = CombinedEncrypter.create(public_key.save_pkcs1()) # or CombinedEncrypter(public_key)
decrypter = CombinedDecrypter.create(private_key.save_pkcs1()) # or CombinedDecrypter(private_key)encrypted = encrypter.encrypt(data)
decrypted = decrypter.decrypt(encrypted)assert decrypted['message'] == 'hello combined encryption'
```### Signing and verification
```python
from encryptiontools.signature import Signer, Verifier
from encryptiontools.utils import generate_key_pair
from encryptiontools.exceptions import VerificationErrorpublic_key, private_key = generate_key_pair(512)
data = {'message': 'hello signing and verification'}
signer = Signer.create(private_key.save_pkcs1()) # or Signer(private_key)
verifier = Verifier.create(public_key.save_pkcs1()) # or Verifier(public_key)signature = signer.sign(data)
try:
verifier.verify(data, signature)
assert True
except VerificationError:
assert False
```