Skip to main content

Python Cryptographic (File Locking) Library

Project description

PyFLocker

Python Cryptographic (File Locking) Library

Installation

Use pip or pip3 to install PyFLocker

pip install pyflocker

or

pip3 install pyflocker

Introduction

PyFLocker aims to be your last cryptographic library you will need for both portability and ease of use. Before you read on, check if you agree to at least one of these points:

  • PyCryptodome(x) and pyca/cryptography have very different public interfaces, which makes remembering all the imports very difficult, and leaves you reading docs under deadline.
  • Although pycryptodome(x) is easy to use, it is not as fast as pyca/cryptography.
  • The interface of pyca/cryptography is very difficult to use, let alone remember the import:
    from cryptography.hazmat.primitives.ciphers.algorithms import AES
    from cryptography.hazmat.primitives.ciphers import Modes
    ...
    from cryptography.hazmat.backends import default_backend
    # and so on...
    
  • You wish that only if pyca/cryptography would have been as easy to use as Pycryptodome(x), it would have made life more easy.
  • You sometimes think that the file locking script you wrote were faster somehow and played with both backends very well, but you weren't sure what to do.
    • And all the other solutions (and nonsolutions!) on the internet just confuses you more!

Look no more, you have arrived at the right destination!


PS: At least, those were my points which irritated me when I first used those libraries :)

Usage Overview

Not a "Yet Another Cryptographic Library"

PyFLocker provides you a seamless interface to both the backends, and switching is very easy:

from pyflocker.ciphers import AES, Backends
enc = AES.new(True, key, AES.MODE_GCM, nonce, backend=Backends.CRYPTOGRAPHY)

Want only a single backend throughout your code?

from pyflocker import set_default_backend, Backends
set_default_backend(Backends.CRYPTODOME)

Ease of Use

PyFLocker provides reasonable defaults wherever possible:

from pyflocker.ciphers import RSA
priv = RSA.generate(2048)
with open('private_key.pem', 'xb') as f:
    f.write(priv.serialize())

Don't believe me, try to do the same operation with pyca/cryptography, or just any other initialization.

In short, the interface is very fluid and easy on developer's mind.


Writing into file or file like objects

This is often a related problem when it comes to encryption, but think no more!

from pyflocker.ciphers import AES, Backends
# ... (key, nonce) already made
f1 = open('MySecretData.txt', 'rb')
f2 = open('MySecretData.txt.enc', 'xb')
enc = AES.new(True, key, AES.MODE_EAX, nonce,
              backend=Backends.CRYPTOGRAPHY, file=f1)
enc.update_into(f2)
tag = enc.calculate_tag()

You can also use BytesIO in place of file objects.

Directly encrypting files

Just want to encrypt your file with AES, and even with various available modes?

from pyflocker.locker import locker
from pyflocker.ciphers import AES

passwd = b'no not this'
locker('./MySuperSecretFile.txt', passwd, aes_mode=AES.MODE_CFB)  # default is AES-GCM-256
# file stored as MySuperSecretFile.txt.pyflk

Base classes and tools for wrapping more backends

You can even wrap other tools and ciphers, if you are so inclined...

from pyflocker.ciphers import base

@base.cipher
class MyCustomCipher(base.Cipher):
    def update(self, data):
        ...

    def update_into(self):
        ...

    def authenticate(self, data):
        ...

    def calculate_tag(self, data):
        ...

    def finalize(self):
        ...

    @base.finalizer(allow=True)
    def my_other_finalizer(self):
        ...

License

MIT

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

PyFLocker-0.1.5.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyFLocker-0.1.5-py3-none-any.whl (45.8 kB view details)

Uploaded Python 3

File details

Details for the file PyFLocker-0.1.5.tar.gz.

File metadata

  • Download URL: PyFLocker-0.1.5.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for PyFLocker-0.1.5.tar.gz
Algorithm Hash digest
SHA256 da1955fba77163429cde799d8fa029efeb6df0e9844fcad79dd46f37f736226c
MD5 a18a0f56e9a47911bee505269d5ee149
BLAKE2b-256 f6d0474ae877b0cc4ba5391204434312c03dbac4d5c7347dbddbbc309948af03

See more details on using hashes here.

File details

Details for the file PyFLocker-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: PyFLocker-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 45.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for PyFLocker-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e33f9c5b9863a46ac7e1d4971bfe96593b94aa94089ef431cb2ce218d877eb79
MD5 95e1caa797793e70929a5c08c67ba582
BLAKE2b-256 f4875ecd60ee4516fbc2fc0f82252b4ebc0cfcbe3773404590fde7f51f229a7a

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