Tools for encryption and decryption, signing and verification. Use symmetric and asymmetric (RSA-based) encryption.
Project description
Encryption Tools for Python 3
Tools for encryption and decryption, signing and verification. Use symmetric and asymmetric (RSA-based) encryption.
Installation
pip install encryptiontools
Usage
Asymmetric encryption and decryption
from encryptiontools.encryption import AsymmetricEncrypter, AsymmetricDecrypter
from encryptiontools.tools import generate_key_pair
private_key, public_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
from encryptiontools.encryption import SymmetricEncrypter
key = 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.
from encryptiontools.encryption import CombinedEncrypter, CombinedDecrypter
from encryptiontools.tools import generate_key_pair
private_key, public_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
from encryptiontools.signature import Signer, Verifier
from encryptiontools.tools import generate_key_pair
from encryptiontools.exceptions import VerificationError
private_key, public_key = generate_key_pair(512)
data = {'message': 'hello combined encryption'}
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
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
encryptiontools-0.3.1.tar.gz
(6.9 kB
view hashes)
Built Distribution
Close
Hashes for encryptiontools-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f63b495c0cecb2d3e1c4df2de606d1e5ea1ce2b249c5056a426cbd6f37943297 |
|
MD5 | 6c8e18bfdbc93c9624693389ed731d0b |
|
BLAKE2b-256 | a3502530281945ebf59b48a54a7e79f0e8e3b232c2826e7ac91366c047b7389f |