Giter VIP home page Giter VIP logo

encryptiontools-pypi's Introduction

Encryption Tools for Python 3

PyPI package version number Coverage Status Actions Status 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

from encryptiontools.encryption import AsymmetricEncrypter, AsymmetricDecrypter
from encryptiontools.utils import generate_key_pair

public_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

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.utils import generate_key_pair

public_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

from encryptiontools.signature import Signer, Verifier
from encryptiontools.utils import generate_key_pair
from encryptiontools.exceptions import VerificationError

public_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

encryptiontools-pypi's People

Contributors

smoren avatar

Stargazers

Koth Goth avatar  avatar Stanislav avatar  avatar  avatar Anastasia Golubeva avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.