Skip to main content

Python Cryptographic (File Locking) Library

Project description

PyFLocker

CI Coverage Status Code style: black Imports: isort Python Versions Documentation Status

Python Cryptographic (File Locking) Library

Lock as in Lock and Key.

Installation

Use pip or pip3 to install PyFLocker

pip install pyflocker

or

pip3 install pyflocker

Introduction

PyFLocker aims to be a highly stable and easy to use cryptographic library. 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.

  • 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 had been as easy to use as Pycryptodome(x), it would have made life more easy.

  • You sometimes think that the file encryption script you wrote were somehow faster 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!

PyFLocker uses well established libraries as its backends and expands upon them. This gives you the ultimate ability to cherry-pick the primitives from a specific backend without having to worry about backend itself, as PyFLocker handles it for you.

You can find more information in the documentation.

Features

Not a "Yet Another Cryptographic Library"

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

import os
from pyflocker.ciphers import AES, RSA, ECC
from pyflocker.ciphers.backends import Backends

key, nonce = os.urandom(32), os.urandom(16)

# Multiple backends - same API
enc = AES.new(True, key, AES.MODE_EAX, nonce, backend=Backends.CRYPTOGRAPHY)
rpriv = RSA.generate(2048, backend=Backends.CRYPTODOME)
epriv = ECC.generate("x25519", backend=Backends.CRYPTOGRAPHY)

Backend loading is done internally, and if a backend is explicitly specified, that is used as the default.

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:
    key = priv.serialize(passphrase=b"random-chimp-event")
    f.write(key)

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

In short, the API is very stable, clear 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!

import os
from pyflocker.ciphers import AES
from pyflocker.ciphers.backends import Backends

key, nonce = os.urandom(32), os.urandom(16)
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

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

Find more examples here.

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.4.0.tar.gz (48.4 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.4.0-py3-none-any.whl (67.7 kB view details)

Uploaded Python 3

File details

Details for the file pyflocker-0.4.0.tar.gz.

File metadata

  • Download URL: pyflocker-0.4.0.tar.gz
  • Upload date:
  • Size: 48.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-1024-azure

File hashes

Hashes for pyflocker-0.4.0.tar.gz
Algorithm Hash digest
SHA256 24a0443b7156132735df228573506372147cd759c01c0df53483770c71414ad3
MD5 31f2e97f9df7aa1b1e5acccb106000d2
BLAKE2b-256 861aedcc2aa5474887ae8fd00970bd82ed3aa75016d4cbfb2c628550234a4ae3

See more details on using hashes here.

File details

Details for the file pyflocker-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pyflocker-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 67.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-1024-azure

File hashes

Hashes for pyflocker-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d02600ee3b98da6519295378f82be9d35227044d0bf8c519231f826e033b5e1a
MD5 795211b0fc41244986496eae5ade0c63
BLAKE2b-256 8cf92f04f787805a5ff1e71dc4e8bed6307c506b14cc41303b598a622ced9b13

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