Skip to main content

Standardize cryptographic tasks in your application.

Project description

Crypto-Factory

Main purpose of Crypto-Factory library is to provide a common interface to application for cryptographic tasks.

Based on Factory method design pattern, it provides an abstraction layer to define cryptographic recipes as service providers, a 'factory' manager to register and create individual instances, and a standardized client interface to interact with them. With this approach, implementing existing or new cryptographic methods is simplified, more reusable and easier to maintain.

Crypto-Factory do not provides any Cryptographic algorithms on its own but relies on existing Python packages such as pyca/cryptography which is used to define some built-in Crypto providers. These providers can be used as a quick starter or samples for dedicated implementations.
For this purpose, Templates class are also available to design your own recipes using your preferred cryptography packages.

Quick Start

# Import  & initialize
>>> from crypto_factory import CryptoFactory
>>> cf = CryptoFactory()

# Define your Crypto providers configuration
>>> conf_AES = { 
...     # existing service
...     'key' : b'WkqHg8m9RwmE1iPQJAbuJRKmh72vLvUNFepIWrOldKg=',
...     'iv'  : b'vdU1T6NvAZJIlnznSe8gbQ==',
... }


>>> new_key = cf.utils.generate_key()
>>> conf_Fernet = { 
...     # new service
...     'id' : 'new',
...     'builder' : 'FernetServiceBuilder',
...     'tag' : 'FERNET_TAG',
...     'key' : new_key,
... }

# Register both providers
>>> cf.services.register(
...     conf_AES,
...     sid='aes',
...     builder='AESServiceBuilder',
...     tag="AES_TAG",
... )
'aes'

>>> new_mode = cf.services.register(conf_Fernet)
>>> print(new_mode)
'new'

# Encrypt data
>>> old_secret = cf.encrypt('My_Secret', mode='aes', tag=False)
>>> new_secret = cf.encrypt('My_Secret', new_mode)

# Decrypt data
>>> cf.decrypt(old_secret, mode='aes')
'My_Secret'

>>> cf.decrypt(new_secret)  # (mode is not required with tagging)
'My_Secret'

# Decrypt wrong hash
>>> cf.decrypt(old_secret, mode='new')
Traceback (most recent call last):
...
CryptoFactoryError: Unable to decrypt with Crypto service: new

# Rotate cipher from one or more modes to a target one (migration)
>>> secret = cf.rotate(old_secret, from_modes=['aes', ], to_mode='new')
>>> cf.decrypt(secret, mode='new')
'My_Secret'

Features

Current implemented features are:

Client interface:
Symmetric encryption: encrypt, decrypt, rotate.

Factory (Services manager):
To register and call Crypto service providers.

Built-in Crypto providers:
Services for AES & Fernet encryption. (can be used as quick starter or samples to define your own recipes)

Tagging mechanism:
Tag encrypted data to identify provider ; can be enforced or disabled.

Utilities & helpers:
Manage tags & providers, generate random keys, string encoding, ...

Exceptions:
Single CryptoFactoryError class to catch errors. (basic implementation to simplify errors management on client side)

Templates:
Base classes to implement a Crypto services and its related builder(s).

Install

Crypto-Factory is best installed via pip:

$ pip install Crypto-Factory

Or cloning the Git repository and running within it:

$ pip install -e .

Dependencies

In order for Crypto-Factory's installation to succeed, you will need the following:

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

Crypto-Factory-0.0.9.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

Crypto_Factory-0.0.9-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file Crypto-Factory-0.0.9.tar.gz.

File metadata

  • Download URL: Crypto-Factory-0.0.9.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for Crypto-Factory-0.0.9.tar.gz
Algorithm Hash digest
SHA256 6a5cefe8bfbaa4cf9ffc08f60a007beb12cdd4c71e4386007d0dae8cc1516e48
MD5 fa0b5e659cec15a2213f62323a00f6b1
BLAKE2b-256 3ac5a4dd1730e97ac989cf0aeca788b946cd766f2ff9582b99550c3eca5581a4

See more details on using hashes here.

File details

Details for the file Crypto_Factory-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: Crypto_Factory-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for Crypto_Factory-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a1b7af87a09a04450cdf9c3a520b676a89caf2ed9ad517bd1d1ca298de6b6179
MD5 6540809165dc558afb16275a93814e3f
BLAKE2b-256 a132c8bdb7760bc8dc765f87e931b6d2cb14ae3ddb0db0474e746aad7012b4a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page